From e3990ecd322f7972db0331fb2813a5a9025fe6dd Mon Sep 17 00:00:00 2001 From: Jasper Mayone Date: Wed, 18 Nov 2026 11:17:22 -0500 Subject: [PATCH] fix: delete finished job rows after one day --- config/application.rb | 4 ++++ config/recurring.yml | 10 ++++++++++ spec/config/recurring_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 spec/config/recurring_spec.rb diff --git a/config/application.rb b/config/application.rb index 30e0a54..d40d394 100644 --- a/config/application.rb +++ b/config/application.rb @@ -65,6 +65,10 @@ class Application < Rails::Application # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + # How long a finished job row stays (see clear_finished_jobs in + # config/recurring.yml). The row holds the job arguments. + config.solid_queue.clear_finished_jobs_after = 1.day + end end diff --git a/config/recurring.yml b/config/recurring.yml index 443ca15..fc93144 100644 --- a/config/recurring.yml +++ b/config/recurring.yml @@ -115,3 +115,13 @@ expire_identity_governance_proposals: sweep_pending_shares: class: SweepPendingSharesJob schedule: every minute + +# Delete the rows of finished jobs after one day +# (config.solid_queue.clear_finished_jobs_after). A finished row keeps the job +# arguments, and for a magic link or a guardian consent email that includes +# the raw link token. /admin/jobs shows finished jobs only for that day, and +# the last run of a recurring task goes with its job row. A failed job is not +# finished: it stays until a person retries or discards it. +clear_finished_jobs: + command: "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)" + schedule: every hour at minute 12 diff --git a/spec/config/recurring_spec.rb b/spec/config/recurring_spec.rb new file mode 100644 index 0000000..e773b96 --- /dev/null +++ b/spec/config/recurring_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rails_helper" +require "fugit" + +# Solid Queue reads config/recurring.yml only when the worker starts. An entry +# with a typing error stops the worker, drops the task, or fails each time it +# runs, and no other spec sees it. +RSpec.describe "config/recurring.yml" do # rubocop:disable RSpec/DescribeClass + known_keys = %w[class command args schedule queue priority description] + + YAML.load_file(Rails.root.join("config/recurring.yml")).each do |key, options| + describe key do + it "has a schedule that Solid Queue can read" do + expect(Fugit.parse(options["schedule"], multi: :fail)).to be_a(Fugit::Cron) + end + + it "uses only the keys that Solid Queue reads" do + expect(options.keys - known_keys).to be_empty + end + + if options["class"] + it "names a job class that exists" do + expect(options["class"].safe_constantize).to be < ActiveJob::Base + end + else + it "calls a method that exists" do + receiver, method = options.fetch("command").match(/\A([\w:]+)\.(\w+)/).captures + + expect(receiver.constantize).to respond_to(method) + end + end + end + end +end