Class: Collavre::CronSchedulerJob
- Inherits:
-
ApplicationJob
- Object
- ApplicationJob
- Collavre::CronSchedulerJob
- Defined in:
- app/jobs/collavre/cron_scheduler_job.rb
Overview
CronSchedulerJob is a self-scheduling job that runs every minute and picks up dynamically-created recurring tasks (static: false) whose cron schedule matches the current minute. For each match it enqueues the target job (e.g. CronActionJob).
This exists because Solid Queue’s built-in Scheduler only processes static (config-defined) recurring tasks — dynamic ones created via cron_create are ignored by the Scheduler.
Self-scheduling: after each run, the job re-enqueues itself with ‘wait: 1.minute`. Boot-time scheduling is handled by the engine initializer (see collavre/engine.rb).
Duplicate-execution guard: uses Rails.cache with a per-task, per-minute key so that even if this job runs twice in the same minute window, each task fires at most once. (This cache is process-local and acceptable since CronSchedulerJob runs in a single SQ worker process.)
Reschedule guard: uses SolidQueue::Job table (DB-based) to prevent duplicate scheduler chains — works across all environments without shared cache infrastructure.
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/jobs/collavre/cron_scheduler_job.rb', line 28 def perform now = Time.current dynamic_tasks = SolidQueue::RecurringTask.where(static: false) dynamic_tasks.find_each do |task| next unless schedule_matches?(task, now) next if already_dispatched?(task, now) enqueue_task(task) mark_dispatched(task, now) end ensure reschedule end |