From afdb5d3f61118204a1651f2b36d5cbd1f98cfbb3 Mon Sep 17 00:00:00 2001 From: Stefan Vermaas Date: Tue, 13 May 2025 15:59:52 +0200 Subject: [PATCH 1/4] Automatically clean up finished background jobs By default, finished background jobs are now deleted during the night. This ensures old, finished background job records don't linger around. --- .../solid_queue/install/templates/config/recurring.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/generators/solid_queue/install/templates/config/recurring.yml b/lib/generators/solid_queue/install/templates/config/recurring.yml index d045b191..9216f639 100644 --- a/lib/generators/solid_queue/install/templates/config/recurring.yml +++ b/lib/generators/solid_queue/install/templates/config/recurring.yml @@ -8,3 +8,8 @@ # command: "SoftDeletedRecord.due.delete_all" # priority: 2 # schedule: at 5am every day +production: + automatically_cleanup_finished_jobs: + class: SolidQueue::Job.clear_finished_in_batches + queue: default + schedule: at 1am every day From a9bffadfda9447c95ff13b6f4d48036867eaae14 Mon Sep 17 00:00:00 2001 From: Stefan Vermaas Date: Tue, 13 May 2025 16:01:39 +0200 Subject: [PATCH 2/4] Update the README to communicate the changes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7a2ef2c..fb6c0314 100644 --- a/README.md +++ b/README.md @@ -365,7 +365,7 @@ There are several settings that control how Solid Queue works that you can set a - `silence_polling`: whether to silence Active Record logs emitted when polling for both workers and dispatchers—defaults to `true`. - `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. - `preserve_finished_jobs`: whether to keep finished jobs in the `solid_queue_jobs` table—defaults to `true`. -- `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). +- `clear_finished_jobs_after`: period to keep finished jobs around, in case `preserve_finished_jobs` is true — defaults to 1 day. **Note:** `SolidQueue` automatically cleans up the finished jobs at 1 AM. To disable this, remove the `automatically_cleanup_finished_jobs` periodic job from the `recurring.yml` configuration. - `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. From 618c04c97d697aa118984436f58b61fa390efd40 Mon Sep 17 00:00:00 2001 From: Stefan Vermaas Date: Thu, 15 May 2025 13:43:03 +0200 Subject: [PATCH 3/4] Use double quotes to run the deletion command --- .../solid_queue/install/templates/config/recurring.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/solid_queue/install/templates/config/recurring.yml b/lib/generators/solid_queue/install/templates/config/recurring.yml index 9216f639..42595cb2 100644 --- a/lib/generators/solid_queue/install/templates/config/recurring.yml +++ b/lib/generators/solid_queue/install/templates/config/recurring.yml @@ -10,6 +10,6 @@ # schedule: at 5am every day production: automatically_cleanup_finished_jobs: - class: SolidQueue::Job.clear_finished_in_batches + class: "SolidQueue::Job.clear_finished_in_batches" queue: default schedule: at 1am every day From c22703af4e2dcfd8f918a859df2309eb013e69cd Mon Sep 17 00:00:00 2001 From: Stefan Vermaas Date: Thu, 15 May 2025 13:44:07 +0200 Subject: [PATCH 4/4] Use command instead of class for deleting jobs --- .../solid_queue/install/templates/config/recurring.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/solid_queue/install/templates/config/recurring.yml b/lib/generators/solid_queue/install/templates/config/recurring.yml index 42595cb2..705ac171 100644 --- a/lib/generators/solid_queue/install/templates/config/recurring.yml +++ b/lib/generators/solid_queue/install/templates/config/recurring.yml @@ -10,6 +10,6 @@ # schedule: at 5am every day production: automatically_cleanup_finished_jobs: - class: "SolidQueue::Job.clear_finished_in_batches" + command: "SolidQueue::Job.clear_finished_in_batches" queue: default schedule: at 1am every day