Skip to content

Commit

Permalink
Add job_class and queue_name as columns because they will be queried …
Browse files Browse the repository at this point in the history
…in dashboard
  • Loading branch information
bensheldon committed Apr 21, 2023
1 parent 526f9b5 commit cd453dc
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/good_job/base_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def discrete_support?
# The ActiveJob job class, as a string
# @return [String]
def job_class
serialized_params['job_class']
discrete? ? attributes['job_class'] : serialized_params['job_class']
end

def discrete?
Expand Down
9 changes: 8 additions & 1 deletion app/models/good_job/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,13 @@ def perform
if discrete?
transaction do
now = Time.current
discrete_execution = discrete_executions.create!(serialized_params: serialized_params, scheduled_at: (scheduled_at || created_at), created_at: now)
discrete_execution = discrete_executions.create!(
job_class: job_class,
queue_name: queue_name,
serialized_params: serialized_params,
scheduled_at: (scheduled_at || created_at),
created_at: now
)
update!(performed_at: now, executions_count: ((executions_count || 0) + 1))
end
else
Expand Down Expand Up @@ -460,6 +466,7 @@ def executable?
def make_discrete
self.is_discrete = true
self.id = active_job_id
self.job_class = serialized_params['job_class']
self.executions_count ||= 0

current_time = Time.current
Expand Down
2 changes: 2 additions & 0 deletions app/models/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def table_name=(_value)
# Errored but will not be retried
scope :discarded, -> { finished.where.not(error: nil) }

scope :unfinished_undiscrete, -> { where(finished_at: nil, retried_good_job_id: nil, is_discrete: [nil, false]) }

# The job's ActiveJob UUID
# @return [String]
def id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CreateGoodJobs < ActiveRecord::Migration<%= migration_version %>

t.boolean :is_discrete
t.integer :executions_count
t.text :job_class
end

create_table :good_job_batches, id: :uuid do |t|
Expand All @@ -49,6 +50,8 @@ class CreateGoodJobs < ActiveRecord::Migration<%= migration_version %>
t.datetime :scheduled_at
t.datetime :finished_at
t.text :error
t.text :job_class
t.text :queue_name
end

create_table :good_job_processes, id: :uuid do |t|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CreateGoodJobExecutions < ActiveRecord::Migration<%= migration_version %>
t.timestamps

t.uuid :active_job_id, null: false
t.text :job_class
t.text :queue_name
t.jsonb :serialized_params
t.datetime :scheduled_at
t.datetime :finished_at
Expand All @@ -24,6 +26,7 @@ class CreateGoodJobExecutions < ActiveRecord::Migration<%= migration_version %>
change_table :good_jobs do |t|
t.boolean :is_discrete
t.integer :executions_count
t.text :job_class
end
end
end
2 changes: 2 additions & 0 deletions spec/app/models/good_job/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ def job_params
expect(dexecution).to be_present
expect(dexecution).to have_attributes(
active_job_id: good_job.active_job_id,
job_class: good_job.job_class,
queue_name: good_job.queue_name,
created_at: within(0.001).of(good_job.performed_at),
scheduled_at: within(0.001).of(good_job.created_at),
finished_at: within(1.second).of(Time.current),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def change
t.timestamps

t.uuid :active_job_id, null: false
t.text :job_class
t.text :queue_name
t.jsonb :serialized_params
t.datetime :scheduled_at
t.datetime :finished_at
Expand All @@ -24,6 +26,7 @@ def change
change_table :good_jobs do |t|
t.boolean :is_discrete
t.integer :executions_count
t.text :job_class
end
end
end
3 changes: 3 additions & 0 deletions spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "active_job_id", null: false
t.text "job_class"
t.text "queue_name"
t.jsonb "serialized_params"
t.datetime "scheduled_at"
t.datetime "finished_at"
Expand Down Expand Up @@ -74,6 +76,7 @@
t.uuid "batch_callback_id"
t.boolean "is_discrete"
t.integer "executions_count"
t.text "job_class"
t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at"
t.index ["active_job_id"], name: "index_good_jobs_on_active_job_id"
t.index ["batch_callback_id"], name: "index_good_jobs_on_batch_callback_id", where: "(batch_callback_id IS NOT NULL)"
Expand Down

0 comments on commit cd453dc

Please sign in to comment.