Class: Burstflow::Job
- Inherits:
-
Object
- Object
- Burstflow::Job
- Includes:
- ActiveSupport::Rescuable, Callbacks, Initialization, Model, State
- Defined in:
- lib/burstflow/job.rb
Defined Under Namespace
Modules: Callbacks, Initialization, Model, State Classes: InternalError
Constant Summary collapse
- SUSPEND =
'suspend'.freeze
Instance Attribute Summary collapse
-
#payloads ⇒ Object
Returns the value of attribute payloads.
-
#workflow ⇒ Object
Returns the value of attribute workflow.
Instance Method Summary collapse
- #attributes ⇒ Object
- #configure(*args, &block) ⇒ Object
-
#perform ⇒ Object
execute this code by ActiveJob.
- #perform_now ⇒ Object
-
#resume(data) ⇒ Object
execute this code when resumes after suspending.
- #resume_now(data) ⇒ Object
- #save! ⇒ Object
-
#set_output(data) ⇒ Object
store data to be available for next jobs.
-
#suspend ⇒ Object
mark execution as suspended.
Instance Attribute Details
#payloads ⇒ Object
Returns the value of attribute payloads.
18 19 20 |
# File 'lib/burstflow/job.rb', line 18 def payloads @payloads end |
#workflow ⇒ Object
Returns the value of attribute workflow.
18 19 20 |
# File 'lib/burstflow/job.rb', line 18 def workflow @workflow end |
Instance Method Details
#attributes ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/burstflow/job.rb', line 80 def attributes { workflow_id: workflow_id, id: id, klass: klass, params: params, incoming: incoming, outgoing: outgoing, output: output, started_at: started_at, enqueued_at: enqueued_at, finished_at: finished_at, failed_at: failed_at, suspended_at: suspended_at, resumed_at: resumed_at, failure: failure } end |
#configure(*args, &block) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/burstflow/job.rb', line 71 def configure(*args, &block) workflow.with_lock do builder = Burstflow::Workflow::Builder.new(workflow, *args, &block) workflow.flow['jobs_config'] = builder.as_json workflow.save! reload end end |
#perform ⇒ Object
execute this code by ActiveJob. You may return Burstflow::Job::SUSPEND to suspend job, or call suspend method
34 |
# File 'lib/burstflow/job.rb', line 34 def perform; end |
#perform_now ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/burstflow/job.rb', line 36 def perform_now run_callbacks :perform do perform end rescue StandardError => exception rescue_with_handler(exception) || raise end |
#resume(data) ⇒ Object
execute this code when resumes after suspending
45 46 47 48 49 |
# File 'lib/burstflow/job.rb', line 45 def resume(data) raise InternalError.new(self, "Can't perform resume: not resumed") unless resumed? set_output(data) end |
#resume_now(data) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/burstflow/job.rb', line 51 def resume_now(data) run_callbacks :resume do resume(data) end rescue StandardError => exception rescue_with_handler(exception) || raise end |
#save! ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/burstflow/job.rb', line 25 def save! workflow.with_lock do workflow.set_job(self) workflow.save! yield if block_given? end end |
#set_output(data) ⇒ Object
store data to be available for next jobs
60 61 62 |
# File 'lib/burstflow/job.rb', line 60 def set_output(data) self.output = data end |
#suspend ⇒ Object
mark execution as suspended
65 66 67 68 69 |
# File 'lib/burstflow/job.rb', line 65 def suspend raise InternalError.new(self, "Can't suspend: not running") unless running? set_output(SUSPEND) end |