Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last_enqueued_time and previous_time to RecurringTask #463

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading