-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract shared methods/scopes into a BaseExecution to share between E…
…xecution and Job models; remove deprecated ActiveJobJob model (#894)
- Loading branch information
1 parent
6318e14
commit 685d80b
Showing
6 changed files
with
49 additions
and
69 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 was deleted.
Oops, something went wrong.
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob | ||
# ActiveRecord model to share behavior between {Job} and {Execution} models | ||
# which both read out of the same table. | ||
class BaseExecution < BaseRecord | ||
self.table_name = 'good_jobs' | ||
|
||
# With a given class name | ||
# @!method job_class | ||
# @!scope class | ||
# @param string [String] Execution class name | ||
# @return [ActiveRecord::Relation] | ||
scope :job_class, ->(name) { where(params_job_class.eq(name)) } | ||
|
||
class << self | ||
def json_string(json, attr) | ||
Arel::Nodes::Grouping.new(Arel::Nodes::InfixOperation.new('->>', json, Arel::Nodes.build_quoted(attr))) | ||
end | ||
|
||
def params_job_class | ||
json_string(arel_table['serialized_params'], 'job_class') | ||
end | ||
|
||
def params_execution_count | ||
Arel::Nodes::InfixOperation.new( | ||
'::', | ||
json_string(arel_table['serialized_params'], 'executions'), | ||
Arel.sql('integer') | ||
) | ||
end | ||
|
||
def coalesce_scheduled_at_created_at | ||
arel_table.coalesce(arel_table['scheduled_at'], arel_table['created_at']) | ||
end | ||
end | ||
|
||
# The ActiveJob job class, as a string | ||
# @return [String] | ||
def job_class | ||
serialized_params['job_class'] | ||
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 was deleted.
Oops, something went wrong.