active_job_resque_solo 0.3.4 → 0.3.5

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
  SHA1:
3
- metadata.gz: f52c7144041b333b7202f5401c36f9e38ff34be5
4
- data.tar.gz: 445c8d4b8352f82eb591240ff0bc8113996a3041
3
+ metadata.gz: 7f7a625183f939325da58db5c523dd6f0af00582
4
+ data.tar.gz: 000a2f1a139b0b19a2936d313e4da15d80baf9ad
5
5
  SHA512:
6
- metadata.gz: 0d1dae5d8415e5137db768b7784b202d5b66d1b429e86e52cf342d34ec80d54dc6b0b93d57634f0f53d9afdb26f4d52469ac7ad0304fc149077b9bb5d1941ff1
7
- data.tar.gz: 59b730d1aa86090baf7c85e8ca719b6befdd4f026739760d1d8931084d23a9f296c07d5e801bee890d76ee71ea4241008a79bffa49de869f2002e3ad0ffd7542
6
+ metadata.gz: 6b71ffc31e5a473eb226fe578cdb5c9970728d90e95f595e1076cf14605a0b765247bcd7c33066f0db92d46c336c668b09eb9cb665dea43a10a6ee92460d2bc2
7
+ data.tar.gz: 40f9efe8a2e915abf5f62e230edbd0d84015b646afaff523ca200eff50aeaf507ec64c63e6606670c5b493e07081f9e292d942f5d5553cef16b7b6e76d872731
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.3.5
2
+
3
+ Adds `solo_any_args` directive that will only allow one instance of a job class in the queue regardless of any arguments.
4
+
1
5
  # 0.3.4
2
6
 
3
7
  * Fix bug that could prevent enqueing with slowly performing locks.
data/README.md CHANGED
@@ -42,6 +42,7 @@ You can control which named arguments are used to determine uniqueness in the qu
42
42
 
43
43
  * `solo_only_args`
44
44
  * `solo_except_args`
45
+ * `solo_any_args`
45
46
 
46
47
  ```ruby
47
48
  class MyJob < ActiveJob::Base
@@ -74,6 +75,25 @@ class MyJob < ActiveJob::Base
74
75
  end
75
76
  end
76
77
  ```
78
+
79
+ Specify `solo_any_args` to allow only one instance of your job to be enqueued or executing at any given
80
+ time regardless of the arugments used in each instance.
81
+
82
+ `solo_any_args` overrides `solo_only_args` and `solo_except_args`.
83
+
84
+ ```ruby
85
+ class MyJob < ActiveJob::Base
86
+
87
+ include ActiveJob::Plugins::Resque::Solo
88
+
89
+ solo_any_args
90
+
91
+ queue_as :default
92
+
93
+ def perform(user: nil)
94
+ end
95
+ end
96
+ ```
77
97
  ## Locking
78
98
 
79
99
  Solo uses an internal locking mechanism to prevent multiple processes from
@@ -14,6 +14,10 @@ module ActiveJob
14
14
  end
15
15
 
16
16
  module ClassMethods
17
+ def solo_any_args
18
+ @solo_any_args = true
19
+ end
20
+
17
21
  def solo_only_args(*args)
18
22
  @solo_only_args = args.compact.map(&:to_s).uniq
19
23
  raise ArgumentError, "solo_only_args requires one or more field names" if @solo_only_args.empty?
@@ -25,7 +29,7 @@ module ActiveJob
25
29
  end
26
30
 
27
31
  def solo_inspector
28
- @solo_inspector ||= Inspector.new(@solo_only_args, @solo_except_args, @solo_lock_key_prefix)
32
+ @solo_inspector ||= Inspector.new(@solo_any_args, @solo_only_args, @solo_except_args, @solo_lock_key_prefix)
29
33
  end
30
34
 
31
35
  def solo_lock_key_prefix(key_prefix)
@@ -8,7 +8,8 @@ module ActiveJob
8
8
  module Solo
9
9
  class Inspector
10
10
 
11
- def initialize(only_args, except_args, lock_key_prefix)
11
+ def initialize(any_args, only_args, except_args, lock_key_prefix)
12
+ @any_args = !!any_args
12
13
  @only_args = only_args
13
14
  @except_args = except_args || []
14
15
  # always ignore the ActiveJob symbol hash key.
@@ -92,13 +93,17 @@ module ActiveJob
92
93
 
93
94
  def job_args(args)
94
95
  if args.present?
95
- args.map do |arg|
96
- if arg.is_a? Hash
97
- arg.keep_if { |k,v| @only_args.include?(k.to_s) } if @only_args.present?
98
- arg.keep_if { |k,v| !@except_args.include?(k.to_s) } if @except_args.present?
96
+ if @any_args
97
+ args = []
98
+ else
99
+ args.map do |arg|
100
+ if arg.is_a? Hash
101
+ arg.keep_if { |k,v| @only_args.include?(k.to_s) } if @only_args.present?
102
+ arg.keep_if { |k,v| !@except_args.include?(k.to_s) } if @except_args.present?
103
+ end
104
+
105
+ arg
99
106
  end
100
-
101
- arg
102
107
  end
103
108
  end
104
109
 
@@ -1,3 +1,3 @@
1
1
  module ActiveJobResqueSolo
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_job_resque_solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phillip Kinkade
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails