Class: OpenLoam::ScheduledJob
- Inherits:
-
TenantRecord
- Object
- TenantRecord
- OpenLoam::ScheduledJob
- Includes:
- Auditable
- Defined in:
- app/models/open_loam/scheduled_job.rb
Overview
A recurring job that runs on a schedule (cron or interval). Tenant-scoped: a "tenant"-scope schedule enqueues its job in this tenant on schedule; a "system"-scope schedule enqueues once with no tenant context. Audited on config changes (not per run — runs are tracked by last_run_at/next_run_at).
SECURITY: job_class is validated to be a known ActiveJob (see OpenLoam::Scheduler.resolve_job_class) at save AND at enqueue — a scheduler that constantized and ran arbitrary user input would be a code-execution hole.
Constant Summary collapse
- SCOPES =
%w[tenant system].freeze
- LOCK_TTL =
how long a claim holds a due job before another tick may retry it
5.minutes
- STALE_LOCK =
LOCK_TTL
Constants included from Auditable
Instance Method Summary collapse
-
#compute_next_run(from = Time.current) ⇒ Object
The next fire time strictly after
from, in this job's timezone (UTC when unset). - #job_class_constant ⇒ Object
Instance Method Details
#compute_next_run(from = Time.current) ⇒ Object
The next fire time strictly after from, in this job's timezone (UTC when
unset). Stored in next_run_at as UTC.
28 29 30 |
# File 'app/models/open_loam/scheduled_job.rb', line 28 def compute_next_run(from = Time.current) OpenLoam::Cron.next_after(schedule, from: from, zone: timezone.presence || "UTC") end |
#job_class_constant ⇒ Object
32 33 34 |
# File 'app/models/open_loam/scheduled_job.rb', line 32 def job_class_constant OpenLoam::Scheduler.resolve_job_class(job_class) end |