Purge expired RS authorization codes from a recurring job class
CI / Test (pull_request) Successful in 50s
Release Drafter / Update release notes draft (pull_request) Successful in 3s

The recurring cleanup task used a `command:` string, which Solid Queue evals inside SolidQueue::RecurringJob. It failed in production with `uninitialized constant ...::RsAuthorizationCode` and is only visible in Mission Control as SolidQueue::RecurringJob. Move the cleanup into a regular Active Job class so the task is enqueued as PurgeRsAuthorizationCodesJob on the default queue, appears under its own name, and no longer depends on eval'ing a string.
This commit is contained in:
raucao committed 2026-11-27 16:05:18 +04:00
1 parent f5ea0f137c
commit 5c7234e7d4
3 files changed
+47 -1

No files matched your search

@@ -0,0 +1,7 @@
class PurgeRsAuthorizationCodesJob < ApplicationJob
queue_as :default
def perform
RsAuthorizationCode.where(expires_at: ..1.hour.ago).delete_all
end
end
+1 -1
View File
@@ -11,5 +11,5 @@
production:
purge_rs_authorization_codes:
command: "RsAuthorizationCode.where(expires_at: ..1.hour.ago).delete_all"
class: PurgeRsAuthorizationCodesJob
schedule: every hour
@@ -0,0 +1,39 @@
require 'rails_helper'
RSpec.describe PurgeRsAuthorizationCodesJob, type: :job do
let(:user) { create :user }
def create_code(**attrs)
RsAuthorizationCode.create!(
user: user,
client_id: "example.com",
redirect_uri: "https://example.com",
permissions: %w(documents:rw),
code_challenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
code_challenge_method: "S256",
**attrs
)
end
it "deletes codes expired beyond the grace period" do
expired = create_code(expires_at: 2.hours.ago)
expect {
perform_enqueued_jobs { described_class.perform_later }
}.to change(RsAuthorizationCode, :count).by(-1)
expect(RsAuthorizationCode.exists?(expired.id)).to be(false)
end
it "keeps recently expired and still active codes" do
recently_expired = create_code(expires_at: 30.minutes.ago)
active = create_code(expires_at: 10.minutes.from_now)
expect {
perform_enqueued_jobs { described_class.perform_later }
}.not_to change(RsAuthorizationCode, :count)
expect(RsAuthorizationCode.exists?(recently_expired.id)).to be(true)
expect(RsAuthorizationCode.exists?(active.id)).to be(true)
end
end