File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
app/models/solid_queue/process
lib/solid_queue/supervisor Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ module Prunable
10
10
end
11
11
12
12
class_methods do
13
- def prune
13
+ def prune ( excluding : nil )
14
14
SolidQueue . instrument :prune_processes , size : 0 do |payload |
15
- prunable . non_blocking_lock . find_in_batches ( batch_size : 50 ) do |batch |
15
+ prunable . excluding ( excluding ) . non_blocking_lock . find_in_batches ( batch_size : 50 ) do |batch |
16
16
payload [ :size ] += batch . size
17
17
18
18
batch . each ( &:prune )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def stop_maintenance_task
24
24
end
25
25
26
26
def prune_dead_processes
27
- wrap_in_app_executor { SolidQueue ::Process . prune }
27
+ wrap_in_app_executor { SolidQueue ::Process . prune ( excluding : process ) }
28
28
end
29
29
30
30
def fail_orphaned_executions
Original file line number Diff line number Diff line change @@ -121,6 +121,28 @@ class SupervisorTest < ActiveSupport::TestCase
121
121
end
122
122
end
123
123
124
+ test "prune processes with expired heartbeats" do
125
+ pruned = SolidQueue ::Process . register ( kind : "Worker" , pid : 42 , name : "worker-42" )
126
+
127
+ # Simulate expired heartbeats
128
+ SolidQueue ::Process . update_all ( last_heartbeat_at : 10 . minutes . ago )
129
+
130
+ not_pruned = SolidQueue ::Process . register ( kind : "Worker" , pid : 44 , name : "worker-44" )
131
+
132
+ assert_equal 2 , SolidQueue ::Process . count
133
+
134
+ pid = run_supervisor_as_fork ( load_configuration_from : { workers : [ { queues : :background } ] } )
135
+ wait_for_registered_processes ( 4 )
136
+
137
+ terminate_process ( pid )
138
+
139
+ skip_active_record_query_cache do
140
+ assert_equal 1 , SolidQueue ::Process . count
141
+ assert_nil SolidQueue ::Process . find_by ( id : pruned . id )
142
+ assert SolidQueue ::Process . find_by ( id : not_pruned . id ) . present?
143
+ end
144
+ end
145
+
124
146
private
125
147
def assert_registered_workers ( supervisor_pid : nil , count : 1 )
126
148
assert_registered_processes ( kind : "Worker" , count : count , supervisor_pid : supervisor_pid )
You can’t perform that action at this time.
0 commit comments