Module: MaintenanceTasks::Runner
Overview
This class is responsible for running a given Task.
Defined Under Namespace
Classes: EnqueuingError
Instance Method Summary collapse
-
#resume(run) ⇒ TaskJob
Resumes a Task.
-
#run(name:, csv_file: nil, arguments: {}, run_model: Run, metadata: nil) {|run| ... } ⇒ Task
Runs a Task.
Instance Method Details
#resume(run) ⇒ TaskJob
Resumes a Task.
This method re-instantiates and re-enqueues a job for a Run that was previously paused.
66 67 68 69 70 71 |
# File 'app/models/maintenance_tasks/runner.rb', line 66 def resume(run) job = instantiate_job(run) run.job_id = job.job_id run.enqueued! enqueue(run, job) end |
#run(name:, csv_file: nil, arguments: {}, run_model: Run, metadata: nil) {|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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/maintenance_tasks/runner.rb', line 42 def run(name:, csv_file: nil, arguments: {}, run_model: Run, metadata: nil) run = run_model.new(task_name: name, arguments: arguments, metadata: ) 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 |