sidekiq-activerecord-shard 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8381904a8af934466f4f06293c2c5bbf76fa72f2d23071f475b6930f12a8a25
4
- data.tar.gz: a9541f4e5f55f1273d74ca1a860174b36c826baebc3f872dba3e96ae33b28efc
3
+ metadata.gz: e5b2f3dd951bd57abc6d8c9751398ca0d1ce7463d9349afc3471bb3d9f1314d4
4
+ data.tar.gz: a2669c8431a5cb6c45bccb44f79b8c9efecbef1ed5e90e28c8b6f3551b499484
5
5
  SHA512:
6
- metadata.gz: 3a4a9fe58e64c0bb7acbdf789896f5c41e463567eb3f4070201dcb0d1d479491838a40515f5249ff9e5c80e3e0b3c68ce1ab5f0ecfa2e87252702f0a93b7e3dc
7
- data.tar.gz: 0a6a28a40e51c6f1d031d762d93e3026ddd36c5717a5c84e66225828d2678fff701546bac4478278f9116453ba78ae57ac1d806a18422bb1f3d2a090fdd0520e
6
+ metadata.gz: 903d26936d8030a9a80308dd4c4b7eb135f284acfe08d853640d8a11c7b5895eaa7ce16033e1d80cb45dd38edff388166fc5605cf65b3a0293793326575120b3
7
+ data.tar.gz: 6bf6bdc902d59eebbc320ae7b84f1086a861c2786aa230664e951b52247dd5f7b88acc93b1c62ba50176d38d477941819bae4ee06e1500dc5001a8a62adeaf88
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A Sidekiq middleware for supports ActiveRecord Shard with [ActiveSupport:CurrentAttribute](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html).
4
4
 
5
+ > NOTE: This gem can work with sidekiq-cron or other schedulers, because when Schedule perform a job, it can't know the shard name.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -52,6 +54,20 @@ class ApplicationController < ActionController::Base
52
54
  end
53
55
  ```
54
56
 
57
+ ### Perform Job by set shared
58
+
59
+ Some times, you want to perform a job without Request context, or start Job in schedulers.
60
+
61
+ Now use can use `set(shard: "hard_name")` to set shared in directly.
62
+
63
+ ```rb
64
+ # Call job with "other" shard db
65
+ MyJob.set(shard: "other").perform_later
66
+
67
+ # Call job with "primary" shard db
68
+ MyJob.set(shard: "primary").perform_later
69
+ ```
70
+
55
71
  ## Contributing
56
72
 
57
73
  Contribution directions go here.
@@ -6,12 +6,8 @@ module SidekiqActiveRecordShard
6
6
 
7
7
  def call(_jobclass, job, _queue, _redis)
8
8
  # Store shard value in Job arguments
9
- shard = SidekiqActiveRecordShard.config.selected_shard.call
10
- if shard.nil?
11
- raise "No shard selected, SidekiqActiveRecordShard.config.selected_shard return nil."
12
- end
9
+ job["shard"] ||= SidekiqActiveRecordShard.config.selected_shard.call
13
10
 
14
- job["_active_record_shard"] = shard
15
11
  yield
16
12
  end
17
13
  end
@@ -19,7 +15,11 @@ module SidekiqActiveRecordShard
19
15
  class Server
20
16
  include Sidekiq::ServerMiddleware
21
17
  def call(_jobclass, job, _queue, &block)
22
- set_shard(job["_active_record_shard"], &block)
18
+ if job["shard"].nil?
19
+ yield
20
+ else
21
+ set_shard(job["shard"], &block)
22
+ end
23
23
  end
24
24
 
25
25
  # Inspired by ActiveRecord::Middleware::ShardSelector
@@ -1,3 +1,3 @@
1
1
  module SidekiqActiveRecordShard
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-activerecord-shard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee