sidekiq-job-signal 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +23 -1
- data/lib/sidekiq/job_signal/receiver.rb +2 -2
- data/lib/sidekiq/job_signal/server_middleware.rb +27 -10
- data/lib/sidekiq/job_signal/version.rb +1 -1
- data/lib/sidekiq/job_signal/web.rb +1 -1
- data/lib/sidekiq/job_signal.rb +6 -6
- 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: aa69177da872fdf54f62d0834e9c91873e6b0d48482020eca1d47834bfcbe15f
|
4
|
+
data.tar.gz: 0ec3e0052920bc78933e024194624b17b771ecf5241cc890970e6dfdcbfdad1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 118bcc2de0547932c93a784345d45196034298e0181e3e3cfcbf638b914d74a80683b86f1e36ea46b9b760394adb07e44181664669663c3fc162b40aedd41fda
|
7
|
+
data.tar.gz: 8939c6978196a406867be42c898c6d7f03b31475213c8b1aacba892b12d5753577625fa9547c2c728a968108dd897b497d24b2731ea552bb1a08974ced89e1c5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,10 @@ Install the gem and add to the application's Gemfile by executing:
|
|
8
8
|
|
9
9
|
$ bundle add sidekiq-job-signal
|
10
10
|
|
11
|
+
In your Gemfile, specify the gem as:
|
12
|
+
|
13
|
+
gem "sidekiq-job-signal", require: "sidekiq/job_signal"
|
14
|
+
|
11
15
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
16
|
|
13
17
|
$ gem install sidekiq-job-signal
|
@@ -16,14 +20,32 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
20
|
|
17
21
|
```rb
|
18
22
|
Sidekiq::JobSignal.quit(jid: "12345")
|
23
|
+
Sidekiq::JobSignal.quit(job_class: "ExampleJob")
|
19
24
|
|
20
25
|
# log:
|
21
26
|
# Turned #{12345}:#{JobWorkerClass} into a no-op: [1,2,3]"
|
22
27
|
|
28
|
+
# If you want to add the `quitting?` method to your job
|
29
|
+
class ExampleJob
|
30
|
+
include Sidekiq::Job
|
31
|
+
include Sidekiq::JobSignal::Receiver
|
32
|
+
|
33
|
+
def perform
|
34
|
+
if quitting?
|
35
|
+
# finish early...
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
23
40
|
# middleware.rb
|
24
41
|
Sidekiq.configure_server do |config|
|
25
42
|
config.server_middleware do |chain|
|
43
|
+
# Defaults to by_class: false, by_jid: true
|
26
44
|
chain.add ::Sidekiq::JobSignal::ServerMiddleware
|
45
|
+
# OR
|
46
|
+
chain.add ::Sidekiq::JobSignal::ServerMiddleware, by_class: true
|
47
|
+
# OR
|
48
|
+
chain.add ::Sidekiq::JobSignal::ServerMiddleware, by_jid: false, by_class: true
|
27
49
|
end
|
28
50
|
|
29
51
|
Sidekiq::JobSignal.on_quit do |job|
|
@@ -33,7 +55,7 @@ Sidekiq.configure_server do |config|
|
|
33
55
|
end
|
34
56
|
```
|
35
57
|
|
36
|
-
If you like to enable the Sidekiq Web UI for quitting jobs, you can include the following in some kind of initialization file. This will enable a new "Signals" tab.
|
58
|
+
If you'd like to enable the Sidekiq Web UI for quitting jobs, you can include the following in some kind of initialization file. This will enable a new "Signals" tab.
|
37
59
|
|
38
60
|
```rb
|
39
61
|
Sidekiq::Web.register Sidekiq::JobSignal::Web
|
@@ -5,19 +5,36 @@ module Sidekiq
|
|
5
5
|
class ServerMiddleware
|
6
6
|
include ::Sidekiq::ServerMiddleware
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def worker.perform(*args)
|
13
|
-
logger.info "Turned #{jid}:#{self.class} into a no-op: #{args.inspect}"
|
14
|
-
end
|
15
|
-
end
|
8
|
+
def initialize(options = {})
|
9
|
+
@by_jid = options.fetch(:by_jid, true)
|
10
|
+
@by_class = options.fetch(:by_class, false)
|
11
|
+
end
|
16
12
|
|
13
|
+
def call(job, job_payload, _queue)
|
14
|
+
signalled = ::Sidekiq::JobSignal.quitting?(**quit_options(job))
|
15
|
+
logger.debug "#{self.class}.call: signalled=#{signalled}"
|
16
|
+
noop_job(job) if signalled
|
17
17
|
yield
|
18
18
|
ensure
|
19
|
-
logger.
|
20
|
-
::Sidekiq::JobSignal.handlers.each { |handler| handler.call(
|
19
|
+
logger.debug "#{self.class}.call: ensure signalled=#{signalled}"
|
20
|
+
::Sidekiq::JobSignal.handlers.each { |handler| handler.call(job) } if signalled
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :by_jid, :by_class
|
26
|
+
|
27
|
+
def quit_options(job)
|
28
|
+
{}.tap do |options|
|
29
|
+
options[:job_class] = job.class.name if by_class
|
30
|
+
options[:jid] = job.jid if by_jid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def noop_job(job)
|
35
|
+
def job.perform(*args)
|
36
|
+
logger.info "Turned #{jid}:#{self.class} into a no-op: #{args.inspect}"
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
23
40
|
end
|
data/lib/sidekiq/job_signal.rb
CHANGED
@@ -17,29 +17,29 @@ module Sidekiq
|
|
17
17
|
handlers << block
|
18
18
|
end
|
19
19
|
|
20
|
-
def quit(
|
20
|
+
def quit(job_class: "", jid: "")
|
21
21
|
::Sidekiq.redis do |r|
|
22
22
|
r.pipelined do |pipeline|
|
23
23
|
pipeline.set "jobsignal-#{jid}", "quit", ex: 86_400 if jid && !jid.empty?
|
24
|
-
pipeline.set "jobsignal-#{
|
24
|
+
pipeline.set "jobsignal-#{job_class}", "quit", ex: 86_400 if job_class && !job_class.empty?
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def delete_signal(
|
29
|
+
def delete_signal(job_class: "", jid: "")
|
30
30
|
::Sidekiq.redis do |r|
|
31
31
|
r.pipelined do |pipeline|
|
32
32
|
pipeline.del("jobsignal-#{jid}") if jid && !jid.empty?
|
33
|
-
pipeline.del("jobsignal-#{
|
33
|
+
pipeline.del("jobsignal-#{job_class}") if job_class && !job_class.empty?
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def quitting?(
|
38
|
+
def quitting?(job_class: "", jid: "")
|
39
39
|
results = ::Sidekiq.redis do |r|
|
40
40
|
r.pipelined do |pipeline|
|
41
41
|
pipeline.get("jobsignal-#{jid}") if jid && !jid.empty?
|
42
|
-
pipeline.get("jobsignal-#{
|
42
|
+
pipeline.get("jobsignal-#{job_class}") if job_class && !job_class.empty?
|
43
43
|
end
|
44
44
|
end
|
45
45
|
results.include?("quit")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-job-signal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Camara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.4.10
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Signal a job to quit, and block the job from executing through middleware.
|