-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create "discrete"
good_job_executions
table to separate Job records…
… from Execution records and have a 1-to-1 correspondence between `good_jobs` records and Active Job jobs (#928) * Create "discrete" `good_job_executions` table to separate Job records from Execution records * Change time precision in test * Add benchmark script * For discrete executions, id = active_job_id, scheduled_at = created_at if unscheduled * Allow wider time assertions in specs * Delete discrete executions before executions for better resiliency * Rename `perform_expected_at` to simpler `scheduled_at` * Add job_class and queue_name as columns because they will be queried in dashboard
- Loading branch information
1 parent
1b5a16e
commit e5fbe91
Showing
29 changed files
with
742 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob # :nodoc: | ||
class DiscreteExecution < BaseRecord | ||
self.table_name = 'good_job_executions' | ||
|
||
belongs_to :execution, class_name: 'GoodJob::Execution', foreign_key: 'active_job_id', primary_key: 'active_job_id', inverse_of: :discrete_executions, optional: true | ||
belongs_to :job, class_name: 'GoodJob::Job', foreign_key: 'active_job_id', primary_key: 'active_job_id', inverse_of: :discrete_executions, optional: true | ||
|
||
scope :finished, -> { where.not(finished_at: nil) } | ||
|
||
alias_attribute :performed_at, :created_at | ||
|
||
def number | ||
serialized_params.fetch('executions', 0) + 1 | ||
end | ||
|
||
# Time between when this job was expected to run and when it started running | ||
def queue_latency | ||
created_at - scheduled_at | ||
end | ||
|
||
# Time between when this job started and finished | ||
def runtime_latency | ||
(finished_at || Time.current) - performed_at if performed_at | ||
end | ||
|
||
def last_status_at | ||
finished_at || created_at | ||
end | ||
|
||
def status | ||
if finished_at.present? | ||
if error.present? | ||
:retried | ||
elsif error.present? && job.finished_at.present? | ||
:discarded | ||
else | ||
:succeeded | ||
end | ||
else | ||
:running | ||
end | ||
end | ||
|
||
def display_serialized_params | ||
serialized_params.merge({ | ||
_good_job_execution: attributes.except('serialized_params'), | ||
}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.