Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Run instance on Task #1018

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/maintenance_tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def csv_file
def task
@task ||= begin
task = Task.named(task_name).new
task.run = self
if task.attribute_names.any? && arguments.present?
task.assign_attributes(arguments)
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/maintenance_tasks/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def load_constants
end
end

# The Run that is currently being executed.
attr_accessor :run

# The contents of a CSV file to be processed by a Task.
#
# @return [String] the content of the CSV file to process.
Expand Down
5 changes: 5 additions & 0 deletions test/models/maintenance_tasks/run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ class RunTest < ActiveSupport::TestCase
assert_kind_of Maintenance::UpdatePostsTask, run.task
end

test "#task sets run on the Task instance" do
run = Run.new(task_name: "Maintenance::UpdatePostsTask")
assert_equal(run, run.task.run)
end

test "#validate_task_arguments instantiates Task and assigns arguments if Task has parameters" do
run = Run.new(
task_name: "Maintenance::ParamsTask",
Expand Down
Loading