Skip to content

Commit 8a63da1

Browse files
committed
Add an option to sleep between deleted batches when clearing jobs
Useful for row-based replication setups where fast, big deletions can cause problems.
1 parent eb75d09 commit 8a63da1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ There are several settings that control how Solid Queue works that you can set a
298298
- `silence_polling`: whether to silence Active Record logs emitted when polling for both workers and dispatchers—defaults to `true`.
299299
- `supervisor_pidfile`: path to a pidfile that the supervisor will create when booting to prevent running more than one supervisor in the same host, or in case you want to use it for a health check. It's `nil` by default.
300300
- `preserve_finished_jobs`: whether to keep finished jobs in the `solid_queue_jobs` table—defaults to `true`.
301-
- `clear_finished_jobs_after`: period to keep finished jobs around, in case `preserve_finished_jobs` is true—defaults to 1 day. **Note:** Right now, there's no automatic cleanup of finished jobs. You'd need to do this by periodically invoking `SolidQueue::Job.clear_finished_in_batches`, but this will happen automatically in the near future.
301+
- `clear_finished_jobs_after`: period to keep finished jobs around, in case `preserve_finished_jobs` is true—defaults to 1 day. **Note:** Right now, there's no automatic cleanup of finished jobs. You'd need to do this by periodically invoking `SolidQueue::Job.clear_finished_in_batches`, which can be configured as [a recurring task](#recurring-tasks).
302302
- `default_concurrency_control_period`: the value to be used as the default for the `duration` parameter in [concurrency controls](#concurrency-controls). It defaults to 3 minutes.
303303

304304

app/models/solid_queue/job/clearable.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ module Clearable
1010
end
1111

1212
class_methods do
13-
def clear_finished_in_batches(batch_size: 500, finished_before: SolidQueue.clear_finished_jobs_after.ago, class_name: nil)
13+
def clear_finished_in_batches(batch_size: 500, finished_before: SolidQueue.clear_finished_jobs_after.ago, class_name: nil, sleep_between_batches: 0)
1414
loop do
1515
records_deleted = clearable(finished_before: finished_before, class_name: class_name).limit(batch_size).delete_all
16+
sleep(sleep_between_batches) if sleep_between_batches > 0
1617
break if records_deleted == 0
1718
end
1819
end

0 commit comments

Comments
 (0)