module Camunda::ExternalTaskJob

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. @see Camunda::ExternalTask

Public Instance Methods

bpmn_perform(_variables) click to toggle source

Default bpmn_perform which raises an error. Forces user to create their own implementation

# 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) click to toggle source

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. @example

task = Camunda::ExternalTask.fetch_and_lock('CamundaWorkflow').first
CamundaWorkflow::DoSomething.new.perform(task.id, x: 'abcd')

@param id [Integer] of the worker for the locked task @param input_variables [Hash] @raise [Camunda::ExternalTask::SubmissionError] if Camunda does not accept the submission of the task

# 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) click to toggle source

Reports an error if there is a problem with bpmn_perform @param id [Integer] of the process instance @param exception [Camunda::BpmnError] instance of Camunda::BpmnError

# 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) click to toggle source

Reports completion for an external task with output variable set in bpmn_perform. @param id [Integer] of the worker @param variables [Hash] output variables declared in bpmn_perform

# 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) click to toggle source

Reports external task failure to the Camunda process definition and creates an incident report @param id [Integer] of the worker for the process instance @param exception [Object] the exception for the failed task @param input_variables [Hash] given to the process definition

# 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