Class: Camunda::ExternalTask
- Includes:
- VariableSerialization
- Defined in:
- lib/camunda/external_task.rb
Defined Under Namespace
Classes: SubmissionError
Class Method Summary collapse
- .fetch_and_lock(topics, lock_duration: nil, long_polling_duration: nil) ⇒ Object
- .lock_duration ⇒ Object
- .long_polling_duration ⇒ Object
- .max_polling_tasks ⇒ Object
Instance Method Summary collapse
- #bpmn_error(bpmn_exception) ⇒ Object
- #collection_path ⇒ Object
- #complete(variables = {}) ⇒ Object
- #failure(exception, input_variables = {}) ⇒ Object
- #queue_task ⇒ Object
- #run_now ⇒ Object
- #task_class ⇒ Object
- #task_class_name ⇒ Object
- #variables ⇒ Object
- #worker_id ⇒ Object
Methods included from VariableSerialization
Methods inherited from Model
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_duration ⇒ Object
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_duration ⇒ Object
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_tasks ⇒ Object
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.)[:response] end |
#collection_path ⇒ Object
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., errorDetails: variables_information.to_s + exception.)[:response] end |
#queue_task ⇒ Object
59 60 61 |
# File 'lib/camunda/external_task.rb', line 59 def queue_task task_class.perform_later(id, variables) end |
#run_now ⇒ Object
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_class ⇒ Object
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_name ⇒ Object
77 78 79 |
# File 'lib/camunda/external_task.rb', line 77 def task_class_name "#{process_definition_key}::#{activity_id}" end |
#variables ⇒ Object
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_id ⇒ Object
41 42 43 |
# File 'lib/camunda/external_task.rb', line 41 def worker_id self.class.worker_id end |