Class: Camunda::ProcessDefinition

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

Overview

A process definition defines the structure of a process. The ‘key` of a process definition is the logical identifier of the process. It is used throughout the API, most prominently for starting a process instances. The key of a process definition is defined using the `id` property of the corresponding process element in the BPMN XML file.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VariableSerialization

#serialize_variables

Methods inherited from Model

find_by!, log_details?, worker_id

Class Method Details

.process_instance_result(response) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/camunda/process_definition.rb', line 51

def self.process_instance_result(response)
  unless response[:response].status == 200
    raise Camunda::ProcessEngineException,
          "#{response[:parsed_data][:data][:message]} HTTP Status: #{response[:response].status}"
  end

  Camunda::ProcessInstance.new response[:parsed_data][:data]
end

.start_by_key(key, hash = {}) ⇒ Camunda::ProcessInstance

Starts an individual process instance by key and supplies process variables to be included in the process instance. In the example below a business key is provided. A business key is a domain-specific identifier of a process instance, it makes querying for task more efficient. The business key is displayed prominently in applications like Camunda Cockpit.

Examples:

pd = Camunda::ProcessDefinition.start_by_key 'CamundaWorkflow', variables: { x: 'abcd' }, businessKey: 'WorkflowBusinessKey'

Parameters:

  • key (String)

    process definition identifier

  • hash (Hash) (defaults to: {})

    sets variables to be included with starting a process definition

Returns:

Raises:

See Also:



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

def self.start_by_key(key, hash={})
  hash[:variables] = serialize_variables(hash[:variables]) if hash[:variables]
  tenant_id = hash.delete(:tenant_id)
  tenant_id ||= Camunda::Workflow.configuration.tenant_id

  response = post_raw start_path_for_key(key, tenant_id), hash
  process_instance_result(response)
end

.start_path_for_key(key, tenant_id) ⇒ Object

Sets path to include tenant_id if a tenant_id is provided with a process definition on deployment.



45
46
47
48
49
# File 'lib/camunda/process_definition.rb', line 45

def self.start_path_for_key(key, tenant_id)
  path = "process-definition/key/#{key}"
  path << "/tenant-id/#{tenant_id}" if tenant_id
  "#{path}/start"
end

Instance Method Details

#start(hash = {}) ⇒ Camunda::ProcessInstance

Starts an individual process instance for a process definition. The below example shows how to start a process definition after deployment. Starts the process instance by sending a request to the Camunda engine

Examples:

pd = Camunda::Deployment.create(file_names: ['bpmn/diagrams/sample.bpmn']).first
pd.start

Parameters:

  • hash (Hash) (defaults to: {})

    defaults to {} if no variables are provided

Returns:

Raises:



38
39
40
41
42
# File 'lib/camunda/process_definition.rb', line 38

def start(hash={})
  hash[:variables] = serialize_variables(hash[:variables]) if hash[:variables]
  response = self.class.post_raw "process-definition/#{id}/start", hash
  self.class.process_instance_result(response)
end