-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
- Loading branch information
1 parent
3794dbf
commit 37962da
Showing
23 changed files
with
599 additions
and
126 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,63 @@ | ||
# 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 | ||
now = Time.zone.now | ||
actual_start = performed_at || finished_at || now | ||
|
||
actual_start - perform_expected_at unless perform_expected_at >= now | ||
end | ||
|
||
# Time between when this job started and finished | ||
def runtime_latency | ||
(finished_at || Time.zone.now) - performed_at if performed_at | ||
end | ||
|
||
def last_status_at | ||
finished_at || performed_at || perform_expected_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 | ||
elsif (perform_expected_at || created_at) > DateTime.current | ||
if serialized_params.fetch('executions', 0) > 1 | ||
:retried | ||
else | ||
:scheduled | ||
end | ||
elsif performed_at.present? | ||
:running | ||
else | ||
:queued | ||
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
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
29 changes: 29 additions & 0 deletions
29
lib/generators/good_job/templates/update/migrations/05_create_good_job_executions.rb.erb
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,29 @@ | ||
# frozen_string_literal: true | ||
class CreateGoodJobExecutions < ActiveRecord::Migration<%= migration_version %> | ||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.table_exists?(:good_job_executions) | ||
end | ||
end | ||
|
||
create_table :good_job_executions, id: :uuid do |t| | ||
t.timestamps | ||
|
||
t.uuid :active_job_id | ||
t.jsonb :serialized_params | ||
t.datetime :perform_expected_at | ||
t.datetime :finished_at | ||
t.text :error | ||
|
||
t.index [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at | ||
end | ||
|
||
change_table :good_jobs do |t| | ||
t.boolean :is_discrete | ||
t.integer :executions_count | ||
end | ||
end | ||
end |
Oops, something went wrong.