active_job_resque_solo 0.3.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +28 -1
- data/lib/active_job/plugins/resque/solo.rb +6 -1
- data/lib/active_job/plugins/resque/solo/inspector.rb +5 -1
- data/lib/active_job_resque_solo/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c1808a193478339e05f2b63b8c31bf7c0b3721f6295a279c4e7add9490734ca
|
4
|
+
data.tar.gz: 2fa2b9e100de2ca2be8e63fc4f3ffdbaeee737c7c3794203cba27b875bb9c1ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 603308fbd2832fe52d60d78a0fa4e70821a4bdd3b440532cc78d76558a42c31e55fa6ce51c7db9cf2fe1cf16d4cc0ca0cbeff073ea7fb7929b609dfeda8c1846
|
7
|
+
data.tar.gz: 71286eab4097f6aa6eb9ab92d5ae1a71f7c5d78023cb1f3ac63124cdd4d40877be8967f59cbba3a88b40a377dce831396b0b269e9f0ae6262b806498091fbdec
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 1.0.0
|
2
|
+
|
3
|
+
* Breaking change: Allow a job to reschedule itself while it executing but not enqueued.
|
4
|
+
* Adds `solo_self_enqueueing` as an option to control the re-enqueueing behavior. Use `solo_self_enqueueing :prevent` for the behavior prior to version 1.0.0.
|
5
|
+
|
1
6
|
# 0.3.9
|
2
7
|
|
3
8
|
* Add CI test for Ruby 2.5.0.
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ end
|
|
77
77
|
```
|
78
78
|
|
79
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
|
80
|
+
time regardless of the arguments used in each instance.
|
81
81
|
|
82
82
|
`solo_any_args` overrides `solo_only_args` and `solo_except_args`.
|
83
83
|
|
@@ -119,6 +119,29 @@ class MyJob < ActiveJob::Base
|
|
119
119
|
end
|
120
120
|
```
|
121
121
|
|
122
|
+
## Re-enqueueing from within the job
|
123
|
+
|
124
|
+
The default behavior of this gem allows a Job to re-enqueue itself while it is
|
125
|
+
executing. If you know that your job should not be re-enqueueing itself, you can
|
126
|
+
prevent inadvertent re-enqueueing of the job by using `solo_self_enqueueing :prevent`.
|
127
|
+
|
128
|
+
Jobs that `fail` or `raise` an error may be retried by the framework, and are not
|
129
|
+
affected by this option.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
class MyJob < ActiveJob::Base
|
133
|
+
|
134
|
+
include ActiveJob::Plugins::Resque::Solo
|
135
|
+
|
136
|
+
solo_self_enqueueing :prevent
|
137
|
+
|
138
|
+
def perform(*args)
|
139
|
+
MyJob.perform_later # <== this will not enqueue a job because of :prevent, above.
|
140
|
+
raise MyError # <== retries are still allowed
|
141
|
+
end
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
122
145
|
## Duplicate enqueues are possible
|
123
146
|
|
124
147
|
While this plugin will greatly reduce duplicate instances of a job from being
|
@@ -126,6 +149,10 @@ enqueued, a job may be enqueued multiple times if the Redis response times are
|
|
126
149
|
very slow. Slowness could be caused by extremely high load on Redis or networking
|
127
150
|
issues.
|
128
151
|
|
152
|
+
Since duplicate enqueueing of jobs is a possibility, make sure that that your code
|
153
|
+
does not rely on this gem for sensitive, critical sections of code that must not
|
154
|
+
be processed more than once.
|
155
|
+
|
129
156
|
The locks are acquired for dynamic amounts of time, but expire quickly, typically
|
130
157
|
in one second. Killed workers will not leave long-lived, orphaned locks to
|
131
158
|
adversely block jobs from being enqueued.
|
@@ -29,7 +29,7 @@ module ActiveJob
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def solo_inspector
|
32
|
-
@solo_inspector ||= Inspector.new(@solo_any_args, @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, @solo_self_enqueueing)
|
33
33
|
end
|
34
34
|
|
35
35
|
def solo_lock_key_prefix(key_prefix)
|
@@ -37,6 +37,11 @@ module ActiveJob
|
|
37
37
|
raise ArgumentError, "solo_lock_key_prefix cannot be blank or only spaces." if @solo_lock_key_prefix.blank?
|
38
38
|
|
39
39
|
end
|
40
|
+
|
41
|
+
def solo_self_enqueueing(setting)
|
42
|
+
raise ArgumentError, "solo_self_enqueueing may only be set to :allow or :prevent." unless [:allow, :prevent].include?(setting)
|
43
|
+
@solo_self_enqueueing = (setting == :allow)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
@@ -8,13 +8,14 @@ module ActiveJob
|
|
8
8
|
module Solo
|
9
9
|
class Inspector
|
10
10
|
|
11
|
-
def initialize(any_args, only_args, except_args, lock_key_prefix)
|
11
|
+
def initialize(any_args, only_args, except_args, lock_key_prefix, self_enqueuing)
|
12
12
|
@any_args = !!any_args
|
13
13
|
@only_args = only_args
|
14
14
|
@except_args = except_args || []
|
15
15
|
# always ignore the ActiveJob symbol hash key.
|
16
16
|
@except_args << "_aj_symbol_keys" unless @except_args.include?("_aj_symbol_keys")
|
17
17
|
@lock_key_prefix = lock_key_prefix.present? ? lock_key_prefix : "ajr_solo"
|
18
|
+
@self_enqueueing = self_enqueuing
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.resque_present?
|
@@ -63,7 +64,10 @@ module ActiveJob
|
|
63
64
|
is_executing = ::Resque.workers.any? do |worker|
|
64
65
|
processing = worker.processing
|
65
66
|
next false if processing.blank?
|
67
|
+
|
66
68
|
args = processing["payload"]["args"][0]
|
69
|
+
next false if (@self_enqueueing.nil? || @self_enqueueing) && args['job_id'] == job.job_id
|
70
|
+
|
67
71
|
job_with_args_eq?(job_class, job_arguments, args)
|
68
72
|
end
|
69
73
|
|
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip Kinkade
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.7.
|
135
|
+
rubygems_version: 2.7.6
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Prevents duplicate ActiveJob+Resque jobs from being enqueued.
|