File tree Expand file tree Collapse file tree 5 files changed +59
-41
lines changed Expand file tree Collapse file tree 5 files changed +59
-41
lines changed Original file line number Diff line number Diff line change 2
2
3
3
module SolidQueue
4
4
class Dispatcher < Processes ::Base
5
- include Processes ::Runnable , Processes :: Poller
5
+ include Processes ::Poller
6
6
7
7
attr_accessor :batch_size , :concurrency_maintenance , :recurring_schedule
8
8
@@ -20,13 +20,9 @@ def initialize(**options)
20
20
end
21
21
22
22
private
23
- def run
23
+ def poll
24
24
batch = dispatch_next_batch
25
-
26
- unless batch . size > 0
27
- procline "waiting"
28
- interruptible_sleep ( polling_interval )
29
- end
25
+ batch . size
30
26
end
31
27
32
28
def dispatch_next_batch
@@ -51,6 +47,10 @@ def unload_recurring_schedule
51
47
recurring_schedule . unload_tasks
52
48
end
53
49
50
+ def set_procline
51
+ procline "waiting"
52
+ end
53
+
54
54
def metadata
55
55
super . merge ( batch_size : batch_size , concurrency_maintenance_interval : concurrency_maintenance &.interval , recurring_schedule : recurring_schedule . tasks . presence )
56
56
end
Original file line number Diff line number Diff line change @@ -4,11 +4,39 @@ module SolidQueue::Processes
4
4
module Poller
5
5
extend ActiveSupport ::Concern
6
6
7
+ include Runnable
8
+
7
9
included do
8
10
attr_accessor :polling_interval
9
11
end
10
12
11
13
private
14
+ def run
15
+ if mode . async?
16
+ @thread = Thread . new { start_loop }
17
+ else
18
+ start_loop
19
+ end
20
+ end
21
+
22
+ def start_loop
23
+ loop do
24
+ break if shutting_down?
25
+
26
+ wrap_in_app_executor do
27
+ unless poll > 0
28
+ interruptible_sleep ( polling_interval )
29
+ end
30
+ end
31
+ end
32
+ ensure
33
+ run_callbacks ( :shutdown ) { shutdown }
34
+ end
35
+
36
+ def poll
37
+ raise NotImplementedError
38
+ end
39
+
12
40
def with_polling_volume
13
41
if SolidQueue . silence_polling?
14
42
ActiveRecord ::Base . logger . silence { yield }
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ module Runnable
8
8
9
9
def start
10
10
@stopping = false
11
-
12
11
run_callbacks ( :boot ) { boot }
13
- start_loop
12
+
13
+ run
14
14
end
15
15
16
16
def stop
@@ -26,28 +26,12 @@ def mode
26
26
end
27
27
28
28
def boot
29
- register_signal_handlers if supervised?
30
- SolidQueue . logger . info ( "[SolidQueue] Starting #{ self } " )
31
- end
32
-
33
- def start_loop
34
- if mode . async?
35
- @thread = Thread . new { do_start_loop }
36
- else
37
- do_start_loop
29
+ if supervised?
30
+ register_signal_handlers
31
+ set_procline
38
32
end
39
- end
40
33
41
- def do_start_loop
42
- loop do
43
- break if shutting_down?
44
-
45
- wrap_in_app_executor do
46
- run
47
- end
48
- end
49
- ensure
50
- run_callbacks ( :shutdown ) { shutdown }
34
+ SolidQueue . logger . info ( "[SolidQueue] Starting #{ self } " )
51
35
end
52
36
53
37
def shutting_down?
@@ -70,6 +54,9 @@ def all_work_completed?
70
54
false
71
55
end
72
56
57
+ def set_procline
58
+ end
59
+
73
60
def running_inline?
74
61
mode . inline?
75
62
end
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def supervised_by(process)
14
14
end
15
15
16
16
private
17
+ def set_procline
18
+ procline "waiting"
19
+ end
20
+
17
21
def supervisor_went_away?
18
22
supervised? && supervisor &.pid != ::Process . ppid
19
23
end
Original file line number Diff line number Diff line change 2
2
3
3
module SolidQueue
4
4
class Worker < Processes ::Base
5
- include Processes ::Runnable , Processes :: Poller
5
+ include Processes ::Poller
6
6
7
7
attr_accessor :queues , :pool
8
8
@@ -15,22 +15,17 @@ def initialize(**options)
15
15
end
16
16
17
17
private
18
- def run
19
- polled_executions = poll
20
-
21
- if polled_executions . size > 0
22
- procline "performing #{ polled_executions . count } jobs"
23
-
24
- polled_executions . each do |execution |
18
+ def poll
19
+ claim_executions . then do |executions |
20
+ executions . each do |execution |
25
21
pool . post ( execution )
26
22
end
27
- else
28
- procline "waiting for jobs in #{ queues . join ( "," ) } "
29
- interruptible_sleep ( polling_interval )
23
+
24
+ executions . size
30
25
end
31
26
end
32
27
33
- def poll
28
+ def claim_executions
34
29
with_polling_volume do
35
30
SolidQueue ::ReadyExecution . claim ( queues , pool . idle_threads , process . id )
36
31
end
@@ -47,6 +42,10 @@ def all_work_completed?
47
42
SolidQueue ::ReadyExecution . aggregated_count_across ( queues ) . zero?
48
43
end
49
44
45
+ def set_procline
46
+ procline "waiting for jobs in #{ queues . join ( "," ) } "
47
+ end
48
+
50
49
def metadata
51
50
super . merge ( queues : queues . join ( "," ) , thread_pool_size : pool . size )
52
51
end
You can’t perform that action at this time.
0 commit comments