Class: Camunda::ExternalTask

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

Defined Under Namespace

Classes: SubmissionError

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



67
68
69
70
71
72
73
74
75
# File 'lib/camunda/external_task.rb', line 67

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



45
46
47
# File 'lib/camunda/external_task.rb', line 45

def collection_path
  self.class.collection_path
end

#complete(variables = {}) ⇒ Object



33
34
35
36
37
38
39
# 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]
      .tap do |response|
    raise SubmissionError, response.body[:data][:message] unless response.success?
  end
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" if input_variables.present?
  self.class.post_raw("#{collection_path}/#{id}/failure",
                      workerId: worker_id, errorMessage: exception.message,
                      errorDetails: variables_information.to_s + exception.full_message)[:response]
end

#queue_taskObject



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

def queue_task
  task_class.perform_later(id, variables)
end

#run_nowObject



63
64
65
# File 'lib/camunda/external_task.rb', line 63

def run_now
  task_class_name.safe_constantize.perform_now id, variables
end

#task_classObject



81
82
83
84
85
# File 'lib/camunda/external_task.rb', line 81

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

#task_class_nameObject



77
78
79
# File 'lib/camunda/external_task.rb', line 77

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

#variablesObject



49
50
51
52
53
54
55
56
57
# File 'lib/camunda/external_task.rb', line 49

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

#worker_idObject



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

def worker_id
  self.class.worker_id
end