solid_queue 1.1.3 → 1.1.4
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/README.md +17 -3
- data/app/models/solid_queue/claimed_execution.rb +1 -1
- data/lib/solid_queue/dispatcher.rb +5 -2
- data/lib/solid_queue/lifecycle_hooks.rb +11 -2
- data/lib/solid_queue/processes/og_interruptible.rb +0 -2
- data/lib/solid_queue/processes/process_pruned_error.rb +1 -1
- data/lib/solid_queue/scheduler.rb +2 -1
- data/lib/solid_queue/supervisor.rb +2 -0
- data/lib/solid_queue/version.rb +1 -1
- data/lib/solid_queue/worker.rb +5 -3
- data/lib/solid_queue.rb +11 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 778d9495c79b9b8af00416fd1980250fe6c3213043cbfd31eba5eb5e2795ad13
|
4
|
+
data.tar.gz: 14f929171d65334300648a5f80e59b9f8245034119cfd436d37dae545210c97b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbbd8113e179c49ffcfe707aa38c96f31ac812822d380e7a6739daced30ee029046ec19cf2ea70c81e19c0f1a819412454f1f4eb1a4cfad7cf5fa8b0f88e3021
|
7
|
+
data.tar.gz: c324b1127bbad96191d3c2e268058dd1cec7c29cffe45a511b0899f3e028e86b7ad0cf0638c93100393316bde1e429ab28c828a381c0692b8558c100f296b6f6
|
data/README.md
CHANGED
@@ -313,7 +313,7 @@ and then remove the paused ones. Pausing in general should be something rare, us
|
|
313
313
|
Do this:
|
314
314
|
|
315
315
|
```yml
|
316
|
-
queues: background, backend
|
316
|
+
queues: [ background, backend ]
|
317
317
|
```
|
318
318
|
|
319
319
|
instead of this:
|
@@ -379,6 +379,8 @@ And into two different points in the worker's, dispatcher's and scheduler's life
|
|
379
379
|
- `(worker|dispatcher|scheduler)_start`: after the worker/dispatcher/scheduler has finished booting and right before it starts the polling loop or loading the recurring schedule.
|
380
380
|
- `(worker|dispatcher|scheduler)_stop`: after receiving a signal (`TERM`, `INT` or `QUIT`) and right before starting graceful or immediate shutdown (which is just `exit!`).
|
381
381
|
|
382
|
+
Each of these hooks has an instance of the supervisor/worker/dispatcher/scheduler yielded to the block so that you may read its configuration for logging or metrics reporting purposes.
|
383
|
+
|
382
384
|
You can use the following methods with a block to do this:
|
383
385
|
```ruby
|
384
386
|
SolidQueue.on_start
|
@@ -396,8 +398,20 @@ SolidQueue.on_scheduler_stop
|
|
396
398
|
|
397
399
|
For example:
|
398
400
|
```ruby
|
399
|
-
SolidQueue.on_start
|
400
|
-
|
401
|
+
SolidQueue.on_start do |supervisor|
|
402
|
+
MyMetricsReporter.process_name = supervisor.name
|
403
|
+
|
404
|
+
start_metrics_server
|
405
|
+
end
|
406
|
+
|
407
|
+
SolidQueue.on_stop do |_supervisor|
|
408
|
+
stop_metrics_server
|
409
|
+
end
|
410
|
+
|
411
|
+
SolidQueue.on_worker_start do |worker|
|
412
|
+
MyMetricsReporter.process_name = worker.name
|
413
|
+
MyMetricsReporter.queues = worker.queues.join(',')
|
414
|
+
end
|
401
415
|
```
|
402
416
|
|
403
417
|
These can be called several times to add multiple hooks, but it needs to happen before Solid Queue is started. An initializer would be a good place to do this.
|
@@ -92,7 +92,7 @@ class SolidQueue::ClaimedExecution < SolidQueue::Execution
|
|
92
92
|
|
93
93
|
private
|
94
94
|
def execute
|
95
|
-
ActiveJob::Base.execute(job.arguments)
|
95
|
+
ActiveJob::Base.execute(job.arguments.merge("provider_job_id" => job.id))
|
96
96
|
Result.new(true, nil)
|
97
97
|
rescue Exception => e
|
98
98
|
Result.new(false, e)
|
@@ -3,12 +3,13 @@
|
|
3
3
|
module SolidQueue
|
4
4
|
class Dispatcher < Processes::Poller
|
5
5
|
include LifecycleHooks
|
6
|
-
|
6
|
+
attr_reader :batch_size
|
7
7
|
|
8
8
|
after_boot :run_start_hooks
|
9
9
|
after_boot :start_concurrency_maintenance
|
10
10
|
before_shutdown :stop_concurrency_maintenance
|
11
|
-
|
11
|
+
before_shutdown :run_stop_hooks
|
12
|
+
after_shutdown :run_exit_hooks
|
12
13
|
|
13
14
|
def initialize(**options)
|
14
15
|
options = options.dup.with_defaults(SolidQueue::Configuration::DISPATCHER_DEFAULTS)
|
@@ -25,6 +26,8 @@ module SolidQueue
|
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
29
|
+
attr_reader :concurrency_maintenance
|
30
|
+
|
28
31
|
def poll
|
29
32
|
batch = dispatch_next_batch
|
30
33
|
|
@@ -5,7 +5,7 @@ module SolidQueue
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
mattr_reader :lifecycle_hooks, default: { start: [], stop: [] }
|
8
|
+
mattr_reader :lifecycle_hooks, default: { start: [], stop: [], exit: [] }
|
9
9
|
end
|
10
10
|
|
11
11
|
class_methods do
|
@@ -17,7 +17,12 @@ module SolidQueue
|
|
17
17
|
self.lifecycle_hooks[:stop] << block
|
18
18
|
end
|
19
19
|
|
20
|
+
def on_exit(&block)
|
21
|
+
self.lifecycle_hooks[:exit] << block
|
22
|
+
end
|
23
|
+
|
20
24
|
def clear_hooks
|
25
|
+
self.lifecycle_hooks[:exit] = []
|
21
26
|
self.lifecycle_hooks[:start] = []
|
22
27
|
self.lifecycle_hooks[:stop] = []
|
23
28
|
end
|
@@ -32,9 +37,13 @@ module SolidQueue
|
|
32
37
|
run_hooks_for :stop
|
33
38
|
end
|
34
39
|
|
40
|
+
def run_exit_hooks
|
41
|
+
run_hooks_for :exit
|
42
|
+
end
|
43
|
+
|
35
44
|
def run_hooks_for(event)
|
36
45
|
self.class.lifecycle_hooks.fetch(event, []).each do |block|
|
37
|
-
|
46
|
+
block.call(self)
|
38
47
|
rescue Exception => exception
|
39
48
|
handle_thread_error(exception)
|
40
49
|
end
|
@@ -4,7 +4,7 @@ module SolidQueue
|
|
4
4
|
module Processes
|
5
5
|
class ProcessPrunedError < RuntimeError
|
6
6
|
def initialize(last_heartbeat_at)
|
7
|
-
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at}")
|
7
|
+
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at})")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -5,12 +5,13 @@ module SolidQueue
|
|
5
5
|
include Processes::Runnable
|
6
6
|
include LifecycleHooks
|
7
7
|
|
8
|
-
|
8
|
+
attr_reader :recurring_schedule
|
9
9
|
|
10
10
|
after_boot :run_start_hooks
|
11
11
|
after_boot :schedule_recurring_tasks
|
12
12
|
before_shutdown :unschedule_recurring_tasks
|
13
13
|
before_shutdown :run_stop_hooks
|
14
|
+
after_shutdown :run_exit_hooks
|
14
15
|
|
15
16
|
def initialize(recurring_tasks:, **options)
|
16
17
|
@recurring_schedule = RecurringSchedule.new(recurring_tasks)
|
data/lib/solid_queue/version.rb
CHANGED
data/lib/solid_queue/worker.rb
CHANGED
@@ -6,14 +6,16 @@ module SolidQueue
|
|
6
6
|
|
7
7
|
after_boot :run_start_hooks
|
8
8
|
before_shutdown :run_stop_hooks
|
9
|
+
after_shutdown :run_exit_hooks
|
9
10
|
|
10
|
-
|
11
|
-
attr_accessor :queues, :pool
|
11
|
+
attr_reader :queues, :pool
|
12
12
|
|
13
13
|
def initialize(**options)
|
14
14
|
options = options.dup.with_defaults(SolidQueue::Configuration::WORKER_DEFAULTS)
|
15
15
|
|
16
|
-
|
16
|
+
# Ensure that the queues array is deep frozen to prevent accidental modification
|
17
|
+
@queues = Array(options[:queues]).map(&:freeze).freeze
|
18
|
+
|
17
19
|
@pool = Pool.new(options[:threads], on_idle: -> { wake_up })
|
18
20
|
|
19
21
|
super(**options)
|
data/lib/solid_queue.rb
CHANGED
@@ -41,30 +41,20 @@ module SolidQueue
|
|
41
41
|
mattr_accessor :clear_finished_jobs_after, default: 1.day
|
42
42
|
mattr_accessor :default_concurrency_control_period, default: 3.minutes
|
43
43
|
|
44
|
-
delegate :on_start, :on_stop, to: Supervisor
|
44
|
+
delegate :on_start, :on_stop, :on_exit, to: Supervisor
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def on_worker_stop(...)
|
51
|
-
Worker.on_stop(...)
|
52
|
-
end
|
53
|
-
|
54
|
-
def on_dispatcher_start(...)
|
55
|
-
Dispatcher.on_start(...)
|
56
|
-
end
|
57
|
-
|
58
|
-
def on_dispatcher_stop(...)
|
59
|
-
Dispatcher.on_stop(...)
|
60
|
-
end
|
46
|
+
[ Dispatcher, Scheduler, Worker ].each do |process|
|
47
|
+
define_singleton_method(:"on_#{process.name.demodulize.downcase}_start") do |&block|
|
48
|
+
process.on_start(&block)
|
49
|
+
end
|
61
50
|
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
define_singleton_method(:"on_#{process.name.demodulize.downcase}_stop") do |&block|
|
52
|
+
process.on_stop(&block)
|
53
|
+
end
|
65
54
|
|
66
|
-
|
67
|
-
|
55
|
+
define_singleton_method(:"on_#{process.name.demodulize.downcase}_exit") do |&block|
|
56
|
+
process.on_exit(&block)
|
57
|
+
end
|
68
58
|
end
|
69
59
|
|
70
60
|
def supervisor?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rosa Gutierrez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|