Skip to content

Commit

Permalink
Expose Run Id to Task Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenprater committed Nov 6, 2024
1 parent 74849f3 commit 2ab5ab0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/jobs/concerns/maintenance_tasks/task_job_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def task_iteration(input)
def before_perform
@run = arguments.first
@task = @run.task
@task.run_id = @run.id
if @task.has_csv_content?
@task.csv_content = @run.csv_file.download
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/maintenance_tasks/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class NotFoundError < NameError; end

define_callbacks :start, :complete, :error, :cancel, :pause, :interrupt

attr_accessor :run_id

class << self
# Finds a Task with the given name.
#
Expand Down
6 changes: 6 additions & 0 deletions test/jobs/maintenance_tasks/task_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class TaskJobTest < ActiveJob::TestCase
assert_no_enqueued_jobs
end

test ".perform sets the run_id on the task instance" do
TaskJob.perform_now(@run)

assert_equal @run.id, @run.task.run_id
end

test ".perform doesn't run a cancelled job" do
freeze_time
TaskJob.perform_later(@run)
Expand Down

0 comments on commit 2ab5ab0

Please sign in to comment.