Module: Camunda::ExternalTaskJob
- Included in:
- CamundaJob
- Defined in:
- lib/camunda/external_task_job.rb
Overview
Camunda::ExternalTaskJob module is included in the generated bpmn_classes for ActiveJob and handles the task completion or failure for a given worker that has been locked to be performed.
Instance Method Summary collapse
-
#bpmn_perform(_variables) ⇒ Object
Default bpmn_perform which raises an error.
-
#perform(id, input_variables) ⇒ Object
Performs the external task for the process definition and processes completion or throws an error.
-
#report_bpmn_error(id, exception) ⇒ Object
Reports an error if there is a problem with bpmn_perform.
-
#report_completion(id, variables) ⇒ Object
Reports completion for an external task with output variable set in bpmn_perform.
-
#report_failure(id, exception, input_variables) ⇒ Object
Reports external task failure to the Camunda process definition and creates an incident report.
Instance Method Details
#bpmn_perform(_variables) ⇒ Object
Default bpmn_perform which raises an error. Forces user to create their own implementation
57 58 59 |
# File 'lib/camunda/external_task_job.rb', line 57 def bpmn_perform(_variables) raise StandardError, "Please define this method which takes a hash of variables and returns a hash of variables" end |
#perform(id, input_variables) ⇒ Object
Performs the external task for the process definition and processes completion or throws an error. The below example shows how to run a task based off of our generated classes from the bpmn_classes generator from the sample.bpmn file provided.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/camunda/external_task_job.rb', line 14 def perform(id, input_variables) output_variables = bpmn_perform(input_variables) output_variables = {} unless output_variables.is_a?(Hash) report_completion id, output_variables rescue Camunda::BpmnError => e report_bpmn_error id, e rescue Camunda::ExternalTask::SubmissionError => e # We re-raise this so it is not rescued below raise e rescue StandardError => e report_failure id, e, input_variables end |
#report_bpmn_error(id, exception) ⇒ Object
Reports an error if there is a problem with bpmn_perform
50 51 52 53 54 |
# File 'lib/camunda/external_task_job.rb', line 50 def report_bpmn_error(id, exception) # Submit bpmn error state to Camunda using # POST /external-task/{id}/bpmnError Camunda::ExternalTask.new(id: id).bpmn_error(exception) end |
#report_completion(id, variables) ⇒ Object
Reports completion for an external task with output variable set in bpmn_perform.
31 32 33 34 35 |
# File 'lib/camunda/external_task_job.rb', line 31 def report_completion(id, variables) # Submit to Camunda using # POST /external-task/{id}/complete Camunda::ExternalTask.new(id: id).complete(variables) end |
#report_failure(id, exception, input_variables) ⇒ Object
Reports external task failure to the Camunda process definition and creates an incident report
41 42 43 44 45 |
# File 'lib/camunda/external_task_job.rb', line 41 def report_failure(id, exception, input_variables) # Submit error state to Camunda using # POST /external-task/{id}/failure Camunda::ExternalTask.new(id: id).failure(exception, input_variables) end |