Skip to content

Commit

Permalink
Add last_enqueued_time and previous_time to RecurringTask
Browse files Browse the repository at this point in the history
To aid with monitoring for delayed recurring tasks.
  • Loading branch information
rosa committed Dec 20, 2024
1 parent 090edb9 commit 8102fb8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/solid_queue/recurring_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 8102fb8

Please sign in to comment.