Class: AssistantLockCleanupWorker
- Inherits:
-
Object
- Object
- AssistantLockCleanupWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/assistant_lock_cleanup_worker.rb
Overview
Periodic cleanup of stale processing locks on assistant conversations.
When a Sidekiq worker crashes (OOM, hard kill, deploy), the ensure block
in AssistantChatWorker may never run, leaving processing_by_id and
processing_since set indefinitely. This worker clears any locks older
than LOCK_STALE_AFTER so affected conversations become usable again.
Runs every 5 minutes via sidekiq-scheduler.
Constant Summary collapse
- GROUNDING_AUDIT_STALE_AFTER =
Grounding audit requeue limit.
10.minutes
- GROUNDING_AUDIT_REQUEUE_LIMIT =
Grounding lease timestamp pattern.
100- GROUNDING_LEASE_TIMESTAMP_PATTERN =
Constant.
'^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}Z$'
Instance Method Summary collapse
-
#perform ⇒ Object
Runs the job.
Instance Method Details
#perform ⇒ Object
Runs the job.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/workers/assistant_lock_cleanup_worker.rb', line 26 def perform stale_cutoff = AssistantConversation::LOCK_STALE_AFTER.ago cleared = AssistantConversation .where.not(processing_by_id: nil) .where(processing_since: ...stale_cutoff) .update_all(processing_by_id: nil, processing_since: nil) Rails.logger.info("[AssistantLockCleanupWorker] Cleared #{cleared} stale processing lock(s)") if cleared > 0 requeue_stale_grounding_audits end |