Class: StandardId::CleanupExpiredRefreshTokensJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/standard_id/cleanup_expired_refresh_tokens_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(grace_period_seconds: 7.days.to_i) ⇒ Object

Delete refresh tokens that expired or were revoked more than ‘grace_period_seconds` ago. Accepts integer seconds for reliable ActiveJob serialization across all queue adapters.



8
9
10
11
12
13
14
# File 'app/jobs/standard_id/cleanup_expired_refresh_tokens_job.rb', line 8

def perform(grace_period_seconds: 7.days.to_i)
  cutoff = grace_period_seconds.seconds.ago
  deleted = StandardId::RefreshToken
    .where("expires_at < :cutoff OR revoked_at < :cutoff", cutoff: cutoff)
    .delete_all
  Rails.logger.info("[StandardId] Cleaned up #{deleted} expired/revoked refresh tokens older than #{cutoff}")
end