diff --git a/app/jobs/concerns/maintenance_tasks/task_job_concern.rb b/app/jobs/concerns/maintenance_tasks/task_job_concern.rb index bc2915c3..1c9c72c4 100644 --- a/app/jobs/concerns/maintenance_tasks/task_job_concern.rb +++ b/app/jobs/concerns/maintenance_tasks/task_job_concern.rb @@ -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 diff --git a/app/models/maintenance_tasks/task.rb b/app/models/maintenance_tasks/task.rb index 13cba653..9dff3e55 100644 --- a/app/models/maintenance_tasks/task.rb +++ b/app/models/maintenance_tasks/task.rb @@ -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. # diff --git a/test/jobs/maintenance_tasks/task_job_test.rb b/test/jobs/maintenance_tasks/task_job_test.rb index 55195a64..ddfdc03e 100644 --- a/test/jobs/maintenance_tasks/task_job_test.rb +++ b/test/jobs/maintenance_tasks/task_job_test.rb @@ -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)