Class: Camunda::Task

Inherits:
Model
  • Object
show all
Includes:
VariableSerialization
Defined in:
lib/camunda/task.rb

Overview

Finds tasks by business key and task definition and allows you to report a task complete and update process variables. If a business key isn’t supplied when creating a process definition, you can still retrieve UserTasks by using the ‘.find_by` helper.

Examples:

Camunda::Task.find_by(taskDefinitionKey: "UserTask")
# You can get all tasks with the `.all.each` helper
tasks = Camunda::Task.all.each
# And then complete all tasks like so
tasks.each(&:complete!)

See Also:

Defined Under Namespace

Classes: SubmissionError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VariableSerialization

#serialize_variables

Methods inherited from Model

base_path, find_by!, worker_id

Class Method Details

.find_by_business_key_and_task_definition_key!(instance_business_key, task_key) ⇒ Camunda::Task

Examples:

user_task = Camunda::Task.find_by_business_key_and_task_definition_key!("WorkflowBusinessKey","UserTask")

Parameters:

  • instance_business_key (String)

    the process instance business key

  • task_key (String)

    id/key of the user task

Returns:



22
23
24
# File 'lib/camunda/task.rb', line 22

def self.find_by_business_key_and_task_definition_key!(instance_business_key, task_key)
  find_by!(processInstanceBusinessKey: instance_business_key, taskDefinitionKey: task_key)
end

Instance Method Details

#bpmn_error!(error_code, error_message, vars = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/camunda/task.rb', line 38

def bpmn_error!(error_code, error_message, vars={})
  self.class.request(:post, "task/#{id}/bpmnError", errorCode: error_code, errorMessage: error_message,
                                                    variables: serialize_variables(vars))
      .tap do |response|
    raise SubmissionError, response.errors["message"] unless response.errors.blank?
  end
end

#bpmn_escalation!(escalation_code, vars = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/camunda/task.rb', line 46

def bpmn_escalation!(escalation_code, vars={})
  self.class.request(:post, "task/#{id}/bpmnEscalation", escalationCode: escalation_code,
                                                         variables: serialize_variables(vars))
      .tap do |response|
    raise SubmissionError, response.errors["message"] unless response.errors.blank?
  end
end

#complete!(vars = {}) ⇒ Object

Complete a task and updates process variables.

Examples:

user_task = Camunda::Task.find_by_business_key_and_task_definition_key!("WorkflowBusinessKey","UserTask")
user_task.complete!

Parameters:

  • vars (Hash) (defaults to: {})

    variables to be submitted as part of task completion



31
32
33
34
35
36
# File 'lib/camunda/task.rb', line 31

def complete!(vars={})
  self.class.request(:post, "task/#{id}/complete", variables: serialize_variables(vars))
      .tap do |response|
    raise SubmissionError, response.errors["message"] unless response.errors.blank?
  end
end