Class: AcidicJob::Step
- Inherits:
-
Object
- Object
- AcidicJob::Step
- Defined in:
- lib/acidic_job/step.rb
Overview
Each AcidicJob::Step requires two phases: [1] execution and [2] progression
Instance Method Summary collapse
-
#execute ⇒ Object
The execution phase performs the work of the defined step.
-
#initialize(step, run, job, step_result = nil) ⇒ Step
constructor
A new instance of Step.
-
#progress ⇒ Object
The progression phase advances the job run state machine onto the next step.
Constructor Details
#initialize(step, run, job, step_result = nil) ⇒ Step
Returns a new instance of Step.
6 7 8 9 10 11 |
# File 'lib/acidic_job/step.rb', line 6 def initialize(step, run, job, step_result = nil) @step = step @run = run @job = job @step_result = step_result end |
Instance Method Details
#execute ⇒ Object
The execution phase performs the work of the defined step
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/acidic_job/step.rb', line 14 def execute rescued_error = false step_callable = wrap_step_as_acidic_callable @step begin @run.with_lock do @step_result = step_callable.call(@run) end # QUESTION: Can an error not inherit from StandardError rescue StandardError => e rescued_error = e raise e ensure if rescued_error # If we're leaving under an error condition, try to unlock the job # run right away so that another request can try again. begin @run.update_columns(locked_at: nil, error_object: rescued_error) rescue StandardError => e # We're already inside an error condition, so swallow any additional # errors from here and just send them to logs. # TODO: implement and use a logger here puts "Failed to unlock AcidicJob::Run #{@run.id} because of #{e}." end end end end |
#progress ⇒ Object
The progression phase advances the job run state machine onto the next step
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/acidic_job/step.rb', line 43 def progress @run.with_lock do if @step_result.is_a?(FinishedPoint) @job.run_callbacks :finish do @step_result.call(run: @run) end else @step_result.call(run: @run) end end end |