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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -0
- data/lib/active_job/plugins/resque/solo.rb +5 -1
- data/lib/active_job/plugins/resque/solo/inspector.rb +12 -7
- data/lib/active_job_resque_solo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f7a625183f939325da58db5c523dd6f0af00582
|
4
|
+
data.tar.gz: 000a2f1a139b0b19a2936d313e4da15d80baf9ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b71ffc31e5a473eb226fe578cdb5c9970728d90e95f595e1076cf14605a0b765247bcd7c33066f0db92d46c336c668b09eb9cb665dea43a10a6ee92460d2bc2
|
7
|
+
data.tar.gz: 40f9efe8a2e915abf5f62e230edbd0d84015b646afaff523ca200eff50aeaf507ec64c63e6606670c5b493e07081f9e292d942f5d5553cef16b7b6e76d872731
|
data/CHANGELOG.md
CHANGED
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
|
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
|
+
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-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|