diff --git a/app/models/solid_queue/recurring_task.rb b/app/models/solid_queue/recurring_task.rb index 54777531..5363f0a7 100644 --- a/app/models/solid_queue/recurring_task.rb +++ b/app/models/solid_queue/recurring_task.rb @@ -12,6 +12,8 @@ class RecurringTask < Record scope :static, -> { where(static: true) } + has_many :recurring_executions, foreign_key: :task_key, primary_key: :key + mattr_accessor :default_job_class self.default_job_class = RecurringJob @@ -53,6 +55,18 @@ def next_time parsed_schedule.next_time.utc end + def previous_time + parsed_schedule.previous_time.utc + end + + def last_enqueued_time + if recurring_executions.loaded? + recurring_executions.map(&:run_at).max + else + recurring_executions.maximum(:run_at) + end + end + def enqueue(at:) SolidQueue.instrument(:enqueue_recurring_task, task: key, at: at) do |payload| active_job = if using_solid_queue_adapter?