Class: Camunda::ExternalTask

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VariableSerialization

#serialize_variables

Methods inherited from Model

worker_id

Class Method Details

.fetch_and_lock(topics, lock_duration: nil, long_polling_duration: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/camunda/external_task.rb', line 64

def self.fetch_and_lock(topics, lock_duration: nil, long_polling_duration: nil)
  long_polling_duration ||= long_polling_duration()
  lock_duration ||= lock_duration()
  topic_details = Array(topics).map do |topic|
    { topicName: topic, lockDuration: lock_duration }
  end
  fetchAndLock workerId: worker_id, maxTasks: max_polling_tasks, asyncResponseTimeout: long_polling_duration,
               topics: topic_details
end

.lock_durationObject



16
17
18
# File 'lib/camunda/external_task.rb', line 16

def self.lock_duration
  Camunda::Workflow.configuration.lock_duration.in_milliseconds
end

.long_polling_durationObject



8
9
10
# File 'lib/camunda/external_task.rb', line 8

def self.long_polling_duration
  Camunda::Workflow.configuration.long_polling_duration.in_milliseconds
end

.max_polling_tasksObject



12
13
14
# File 'lib/camunda/external_task.rb', line 12

def self.max_polling_tasks
  Camunda::Workflow.configuration.max_polling_tasks
end

Instance Method Details

#bpmn_error(bpmn_exception) ⇒ Object



27
28
29
30
31
# File 'lib/camunda/external_task.rb', line 27

def bpmn_error(bpmn_exception)
  self.class.post_raw("#{collection_path}/#{id}/bpmnError",
                      workerId: worker_id, variables: serialize_variables(bpmn_exception.variables),
                      errorCode: bpmn_exception.error_code, errorMessage: bpmn_exception.message)[:response]
end

#collection_pathObject



42
43
44
# File 'lib/camunda/external_task.rb', line 42

def collection_path
  self.class.collection_path
end

#complete(variables = {}) ⇒ Object



33
34
35
36
# File 'lib/camunda/external_task.rb', line 33

def complete(variables={})
  self.class.post_raw("#{collection_path}/#{id}/complete",
                      workerId: worker_id, variables: serialize_variables(variables))[:response]
end

#failure(exception, input_variables) ⇒ Object



20
21
22
23
24
25
# File 'lib/camunda/external_task.rb', line 20

def failure(exception, input_variables)
  variables_information = "Input variables are #{input_variables.inspect}\n\n"
  self.class.post_raw("#{collection_path}/#{id}/failure",
                      workerId: worker_id, errorMessage: exception.message,
                      errorDetails: variables_information + exception.full_message)[:response]
end

#queue_taskObject



56
57
58
# File 'lib/camunda/external_task.rb', line 56

def queue_task
  task_class.perform_later(id, variables)
end

#run_nowObject



60
61
62
# File 'lib/camunda/external_task.rb', line 60

def run_now
  task_class_name.safe_constantize.perform_now id, variables
end

#task_classObject



78
79
80
81
82
# File 'lib/camunda/external_task.rb', line 78

def task_class
  task_class_name.safe_constantize.tap do |klass|
    raise Camunda::MissingImplementationClass, task_class_name unless klass
  end
end

#task_class_nameObject



74
75
76
# File 'lib/camunda/external_task.rb', line 74

def task_class_name
  "#{process_definition_key}::#{activity_id}"
end

#variablesObject



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

def variables
  super.transform_values do |details|
    if details['type'] == 'Json'
      JSON.parse(details['value'])
    else
      details['value']
    end
  end
end

#worker_idObject



38
39
40
# File 'lib/camunda/external_task.rb', line 38

def worker_id
  self.class.worker_id
end