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.
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/workers/assistant_lock_cleanup_worker.rb', line 16 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) if cleared > 0 Rails.logger.info("[AssistantLockCleanupWorker] Cleared #{cleared} stale processing lock(s)") end end |