Class: Operaton::Bpm::Client::Impl::EngineClient

Inherits:
Object
  • Object
show all
Defined in:
lib/operaton/bpm/client/impl/engine_client.rb

Overview

Mirrors org.operaton.bpm.client.impl.EngineClient

Constant Summary collapse

EXTERNAL_TASK_RESOURCE_PATH =
"/external-task"
EXTERNAL_TASK_PROCESS_RESOURCE_PATH =
"/process-instance"
FETCH_AND_LOCK_RESOURCE_PATH =
"#{EXTERNAL_TASK_RESOURCE_PATH}/fetchAndLock"
ID_PATH_PARAM =
"{id}"
ID_RESOURCE_PATH =
"#{EXTERNAL_TASK_RESOURCE_PATH}/#{ID_PATH_PARAM}"
LOCK_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/lock"
EXTEND_LOCK_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/extendLock"
SET_VARIABLES_RESOURCE_PATH =
"#{EXTERNAL_TASK_PROCESS_RESOURCE_PATH}/#{ID_PATH_PARAM}/variables"
UNLOCK_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/unlock"
COMPLETE_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/complete"
FAILURE_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/failure"
BPMN_ERROR_RESOURCE_PATH =
"#{ID_RESOURCE_PATH}/bpmnError"
NAME_PATH_PARAM =
"{name}"
PROCESS_INSTANCE_RESOURCE_PATH =
"/process-instance"
PROCESS_INSTANCE_ID_RESOURCE_PATH =
"#{PROCESS_INSTANCE_RESOURCE_PATH}/#{ID_PATH_PARAM}"
GET_BINARY_VARIABLE =
"#{PROCESS_INSTANCE_ID_RESOURCE_PATH}/variables/#{NAME_PATH_PARAM}/data"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker_id, max_tasks, async_response_timeout, url_resolver, engine_interaction, use_priority = true, ordering_config = Task::OrderingConfig.empty) ⇒ EngineClient

Returns a new instance of EngineClient.



41
42
43
44
45
46
47
48
49
50
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 41

def initialize(worker_id, max_tasks, async_response_timeout, url_resolver, engine_interaction,
               use_priority = true, ordering_config = Task::OrderingConfig.empty)
  @worker_id = worker_id
  @max_tasks = max_tasks
  @async_response_timeout = async_response_timeout
  @url_resolver = url_resolver.respond_to?(:base_url) ? url_resolver : PermanentUrlResolver.new(url_resolver)
  @engine_interaction = engine_interaction
  @use_priority = use_priority
  @ordering_config = ordering_config
end

Instance Attribute Details

#async_response_timeoutObject (readonly)

Returns the value of attribute async_response_timeout.



38
39
40
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 38

def async_response_timeout
  @async_response_timeout
end

#max_tasksObject (readonly)

Returns the value of attribute max_tasks.



38
39
40
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 38

def max_tasks
  @max_tasks
end

#ordering_configObject (readonly)

Returns the value of attribute ordering_config.



38
39
40
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 38

def ordering_config
  @ordering_config
end

#typed_valuesObject

Returns the value of attribute typed_values.



39
40
41
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 39

def typed_values
  @typed_values
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



38
39
40
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 38

def worker_id
  @worker_id
end

Instance Method Details

#base_urlObject



114
115
116
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 114

def base_url
  @url_resolver.base_url
end

#bpmn_error(task_id, error_code, error_message, variables) ⇒ Object



95
96
97
98
99
100
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 95

def bpmn_error(task_id, error_code, error_message, variables)
  payload = Task::Impl::Dto::BpmnErrorRequestDto.new(
    worker_id, error_code, error_message, typed_values.serialize_variables(variables)
  )
  post_task_request(BPMN_ERROR_RESOURCE_PATH, task_id, payload)
end

#complete(task_id, variables, local_variables) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 69

def complete(task_id, variables, local_variables)
  payload = Task::Impl::Dto::CompleteRequestDto.new(
    worker_id,
    typed_values.serialize_variables(variables),
    typed_values.serialize_variables(local_variables)
  )
  post_task_request(COMPLETE_RESOURCE_PATH, task_id, payload)
end

#extend_lock(task_id, new_duration) ⇒ Object



102
103
104
105
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 102

def extend_lock(task_id, new_duration)
  payload = Task::Impl::Dto::ExtendLockRequestDto.new(worker_id, new_duration)
  post_task_request(EXTEND_LOCK_RESOURCE_PATH, task_id, payload)
end

#failure(task_id, error_message, error_details, retries, retry_timeout, variables, local_variables) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 86

def failure(task_id, error_message, error_details, retries, retry_timeout, variables, local_variables)
  payload = Task::Impl::Dto::FailureRequestDto.new(
    worker_id, error_message, error_details, retries, retry_timeout,
    typed_values.serialize_variables(variables),
    typed_values.serialize_variables(local_variables)
  )
  post_task_request(FAILURE_RESOURCE_PATH, task_id, payload)
end

#fetch_and_lock(topics) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 52

def fetch_and_lock(topics)
  payload = Topic::Impl::Dto::FetchAndLockRequestDto.new(
    worker_id, max_tasks, async_response_timeout, topics, @use_priority, ordering_config
  )
  resource_url = base_url + FETCH_AND_LOCK_RESOURCE_PATH
  @engine_interaction.post_request(resource_url, payload, [Task::Impl::ExternalTaskImpl])
end

#get_local_binary_variable(variable_name, execution_id) ⇒ Object



107
108
109
110
111
112
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 107

def get_local_binary_variable(variable_name, execution_id)
  resource_url = base_url + GET_BINARY_VARIABLE
                 .sub(ID_PATH_PARAM, execution_id)
                 .sub(NAME_PATH_PARAM, variable_name)
  @engine_interaction.get_request(resource_url)
end

#lock(task_id, lock_duration) ⇒ Object



60
61
62
63
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 60

def lock(task_id, lock_duration)
  payload = Task::Impl::Dto::LockRequestDto.new(worker_id, lock_duration)
  post_task_request(LOCK_RESOURCE_PATH, task_id, payload)
end

#set_variables(process_id, variables) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 78

def set_variables(process_id, variables)
  payload = Task::Impl::Dto::SetVariablesRequestDto.new(
    worker_id, typed_values.serialize_variables(variables)
  )
  resource_url = base_url + SET_VARIABLES_RESOURCE_PATH.sub(ID_PATH_PARAM, process_id)
  @engine_interaction.post_request(resource_url, payload, RequestExecutor::VOID)
end

#unlock(task_id) ⇒ Object



65
66
67
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 65

def unlock(task_id)
  post_task_request(UNLOCK_RESOURCE_PATH, task_id, nil)
end

#use_priority?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/operaton/bpm/client/impl/engine_client.rb', line 118

def use_priority?
  @use_priority
end