Class: Utils::Operaton::ProcessClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- Utils::Operaton::ProcessClient
- Defined in:
- lib/bas/utils/operaton/process_client.rb
Overview
Client for deploying BPMN processes and starting process instances in Operaton (Camunda 7 API compatible)
Instance Method Summary collapse
- #deploy_process(file_path, deployment_name:) ⇒ Object
-
#initialize(base_url:) ⇒ ProcessClient
constructor
A new instance of ProcessClient.
- #instance_with_business_key_exists?(process_key, business_key) ⇒ Boolean
- #start_process_instance_by_key(process_key, business_key:, variables: {}) ⇒ Object
Constructor Details
#initialize(base_url:) ⇒ ProcessClient
Returns a new instance of ProcessClient.
19 20 21 22 |
# File 'lib/bas/utils/operaton/process_client.rb', line 19 def initialize(base_url:) @logger = defined?(Rails) ? Rails.logger : Logger.new($stdout) super(base_url: base_url) end |
Instance Method Details
#deploy_process(file_path, deployment_name:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bas/utils/operaton/process_client.rb', line 24 def deploy_process(file_path, deployment_name:) raise "File not found: #{file_path}" unless File.exist?(file_path) raise "File is not readable: #{file_path}" unless File.readable?(file_path) @logger.info "📁 Attempting to read file: #{file_path}" @logger.info "📦 Deployment name: #{deployment_name}" payload = { "deployment-name" => deployment_name, "deploy-changed-only" => "true", "data" => Faraday::Multipart::FilePart.new(file_path, "application/octet-stream", File.basename(file_path)) } post("/deployment/create", payload) end |
#instance_with_business_key_exists?(process_key, business_key) ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bas/utils/operaton/process_client.rb', line 40 def instance_with_business_key_exists?(process_key, business_key) query_params = { processDefinitionKey: process_key, maxResults: 50, active: true } response = get("/history/process-instance", query_params) response.any? { |instance| instance["businessKey"] == business_key } end |
#start_process_instance_by_key(process_key, business_key:, variables: {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bas/utils/operaton/process_client.rb', line 51 def start_process_instance_by_key(process_key, business_key:, variables: {}) json_payload = { businessKey: business_key, variables: format_variables(variables) } post( "/process-definition/key/#{process_key}/start", JSON.generate(json_payload), { "Content-Type" => "application/json" } ) end |