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 provided by Her.

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

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

#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.post_raw("#{self.class.collection_path}/#{id}/complete", variables: serialize_variables(vars))[:response]
      .tap do |response|
    raise SubmissionError, response.body[:data][:message] unless response.success?
  end
end