Module: MaintenanceTasks::Runner
Overview
This class is responsible for running a given Task.
Defined Under Namespace
Classes: EnqueuingError
Instance Method Summary collapse
-
#new ⇒ Object
deprecated
Deprecated.
Use Runner directly instead.
-
#run(name:, csv_file: nil, arguments: {}, run_model: Run) {|run| ... } ⇒ Task
Runs a Task.
Instance Method Details
#new ⇒ Object
Deprecated.
Use MaintenanceTasks::Runner directly instead.
9 10 11 12 13 14 |
# File 'app/models/maintenance_tasks/runner.rb', line 9 def new ActiveSupport::Deprecation.warn( "Use Runner.run instead of Runner.new.run" ) self end |
#run(name:, csv_file: nil, arguments: {}, run_model: Run) {|run| ... } ⇒ Task
Runs a Task.
This method creates a Run record for the given Task name and enqueues the Run. If a CSV file is provided, it is attached to the Run record.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/maintenance_tasks/runner.rb', line 50 def run(name:, csv_file: nil, arguments: {}, run_model: Run) run = run_model.active.find_by(task_name: name) || run_model.new(task_name: name, arguments: arguments) if csv_file run.csv_file.attach(csv_file) run.csv_file.filename = filename(name) end job = instantiate_job(run) run.job_id = job.job_id yield run if block_given? run.enqueued! enqueue(run, job) Task.named(name) end |