camunda-workflow 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de3f5b53f63bf54079ee7c40c5b4484610f5fff5aea834f277c53c2a19061066
4
- data.tar.gz: 9bc948e1114eb799505598a585874070436097ec1ee86396f806457aad8a304c
3
+ metadata.gz: 3968856a19853532f780e7e81b3449a7e9d45bc23f699a22ddc25e400d787318
4
+ data.tar.gz: fa0c4ed150e0fabb72c11bbbff14c1f32b7da908b642511de3fe0e674423ba23
5
5
  SHA512:
6
- metadata.gz: 75e7a0452733b6c14c62a60bcb794c29d5760431721ab85bc138ea3bb35e32ae11803466247de18ec86825f4f057963f9735744c6418b5549f2f0811dd9f13d2
7
- data.tar.gz: f97120868b79674a2dc60c04d7c646fe511da2674113f198da67fcfc6081507fc263edc8713d4631e371c979cea2f9b564f62a846c316856170b8640089e5063
6
+ metadata.gz: e009f167b8de5e94972ae2e98b1dc97ebdd8c927d6034c5b7461b2c3c41c56ab28590fd8546d8d2049c81892fa9cd0a3de37c933cfc9539a8434a5eebd1c0357
7
+ data.tar.gz: 57651fbbc6eafc00625a5ac5d826f2b5192979b961f6164cc46d0b44e2fca15492b0be1889f7aacd0a56f112b997c1040d1aa7b69416895ed16a69078e9c7406
data/CHANGELOG.md CHANGED
@@ -1,13 +1,33 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/amalagaura/camunda-workflow/tree/HEAD)
3
+ ## [v0.2.2](https://github.com/amalagaura/camunda-workflow/tree/v0.2.2) (2020-01-08)
4
4
 
5
- [Full Changelog](https://github.com/amalagaura/camunda-workflow/compare/v0.2.0...HEAD)
5
+ [Full Changelog](https://github.com/amalagaura/camunda-workflow/compare/v0.2.1...v0.2.2)
6
6
 
7
7
  **Closed issues:**
8
8
 
9
+ - The task for Message End Events is on the parent node of camunda:type="external" [\#34](https://github.com/amalagaura/camunda-workflow/issues/34)
10
+ - Error in documentation regarding deployment of BPMN files. [\#32](https://github.com/amalagaura/camunda-workflow/issues/32)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Camunda calls the external task from bpmn:endEvent [\#35](https://github.com/amalagaura/camunda-workflow/pull/35) ([amalagaura](https://github.com/amalagaura))
15
+ - fixed documentation on README [\#33](https://github.com/amalagaura/camunda-workflow/pull/33) ([curatingbits](https://github.com/curatingbits))
16
+
17
+ ## [v0.2.1](https://github.com/amalagaura/camunda-workflow/tree/v0.2.1) (2019-12-28)
18
+
19
+ [Full Changelog](https://github.com/amalagaura/camunda-workflow/compare/v0.2.0...v0.2.1)
20
+
21
+ **Closed issues:**
22
+
23
+ - Include gems via Railtie instead of by copying the .rake file [\#29](https://github.com/amalagaura/camunda-workflow/issues/29)
9
24
  - Remove check for what bpmn\_perform returns. Ignore if not a hash. [\#27](https://github.com/amalagaura/camunda-workflow/issues/27)
10
25
 
26
+ **Merged pull requests:**
27
+
28
+ - Remove startup error instructions [\#31](https://github.com/amalagaura/camunda-workflow/pull/31) ([amalagaura](https://github.com/amalagaura))
29
+ - create railtie to include rake tasks [\#30](https://github.com/amalagaura/camunda-workflow/pull/30) ([curatingbits](https://github.com/curatingbits))
30
+
11
31
  ## [v0.2.0](https://github.com/amalagaura/camunda-workflow/tree/v0.2.0) (2019-12-20)
12
32
 
13
33
  [Full Changelog](https://github.com/amalagaura/camunda-workflow/compare/v0.1.5...v0.2.0)
data/README.md CHANGED
@@ -153,7 +153,7 @@ It will fail to start. Create a postgres database as a service in PCF and bind i
153
153
 
154
154
  ## Usage
155
155
 
156
- ### Add to your Gemfile
156
+ ### Add to your Gemfile
157
157
  ```ruby
158
158
  gem 'camunda-workflow'
159
159
  ```
@@ -162,7 +162,7 @@ It will fail to start. Create a postgres database as a service in PCF and bind i
162
162
  Uses a default name, etc. Below outlines how to deploy a process using the included sample.bpmn file created by the generator. Alternatively you can deploy using Camunda Modeler
163
163
 
164
164
  ```ruby
165
- Camunda::Deployment.create file_name: 'bpmn/diagrams/sample.bpmn'
165
+ Camunda::Deployment.create file_names: ['bpmn/diagrams/sample.bpmn']
166
166
  ```
167
167
  ### Processes
168
168
 
@@ -198,6 +198,16 @@ Poller will need to run in a separate process or thread and needs to be running
198
198
  Camunda::Poller.fetch_and_queue %w[CamundaWorkflow]
199
199
  ```
200
200
 
201
+ #### Running the poller in a separate thread
202
+ We have had success with running a long running thread in a Rails app using [Rufus Scheduler](https://github.com/jmettraux/rufus-scheduler). Something like:
203
+
204
+ ```
205
+ rufus_scheduler.in('10.seconds') do
206
+ Camunda::Poller.fetch_and_queue %w[Topics]
207
+ end
208
+ ```
209
+
210
+
201
211
  #### Fetch tasks For testing from the console
202
212
 
203
213
  ```ruby
@@ -20,9 +20,14 @@ class Camunda::BpmnXML
20
20
 
21
21
  # creates a new instance of Camunda::BpmnXML::Task
22
22
  def external_tasks
23
- @doc.xpath('//*[@camunda:type="external"]').map do |task|
23
+ @doc.xpath('(//bpmn:serviceTask[@camunda:type="external"]|//bpmn:sendTask[@camunda:type="external"])').map do |task|
24
24
  Task.new(task)
25
- end
25
+ end +
26
+ @doc.xpath('//bpmn:endEvent/bpmn:messageEventDefinition[@camunda:type="external"]').map do |child_node|
27
+ task = child_node.parent.dup
28
+ task["topic"] = child_node["topic"]
29
+ Task.new(task)
30
+ end
26
31
  end
27
32
 
28
33
  # We may have tasks with different topics. Returns classes with topics which are the same as the BPMN process id
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/string/inflections.rb'
1
+ require 'active_support/core_ext/string/inflections'
2
2
  require 'active_support/backtrace_cleaner'
3
3
  # External Tasks are the task entity for camunda. We can query the topic and lock the task. After the task
4
4
  # is locked, the external task of the process instance can be worked and completed. Below is an excerpt from the Camunda
@@ -133,6 +133,25 @@ class Camunda::ExternalTask < Camunda::Model
133
133
  topics: topic_details
134
134
  end
135
135
 
136
+ # Locking means that the task is reserved for this worker for a certain duration beginning with the time of fetching and
137
+ # prevents that another worker can fetch the same task while the lock is valid. Locking duration is set in the the
138
+ # Camunda::Workflow configuration. Before an external task can be completed, it must be locked.
139
+ #
140
+ # This method calls fetch_and_lock and then queues the jobs that were retrieved
141
+ # @example
142
+ # task = Camunda::ExternalTask.fetch_and_queue("CamundaWorkflow")
143
+ # @param topics [Array<String>] definition keys
144
+ # @param lock_duration [Integer]
145
+ # @param long_polling_duration [Integer]
146
+ # @return [Camunda::ExternalTask]
147
+ def self.fetch_and_queue(topics, lock_duration: nil, long_polling_duration: nil)
148
+ fetch_and_lock(topics, lock_duration: lock_duration, long_polling_duration: long_polling_duration).each do |task|
149
+ task.queue_task
150
+ rescue Camunda::MissingImplementationClass => e
151
+ task.failure(e)
152
+ end
153
+ end
154
+
136
155
  # Returns the class name which is supposed to implement this task
137
156
  # @return [String] modularized class name of bpmn task implementation
138
157
  def task_class_name
data/lib/camunda/model.rb CHANGED
@@ -3,6 +3,10 @@ require 'her/model'
3
3
  class Camunda::Model
4
4
  include Her::Model
5
5
 
6
+ def self.log_details?
7
+ defined?(Rails) && Rails.env.development?
8
+ end
9
+
6
10
  # We use a lambda so that this is evaluated after Camunda::Workflow.configuration is set
7
11
  api = lambda do
8
12
  # Configuration for Her and Faraday requests and responses
@@ -14,12 +18,15 @@ class Camunda::Model
14
18
  c.use Faraday::Request::BasicAuthentication, Camunda::Workflow.configuration.camunda_user,
15
19
  Camunda::Workflow.configuration.camunda_password
16
20
  # Response
17
- c.use Faraday::Response::Logger, ActiveSupport::Logger.new(STDOUT), bodies: true if Rails.env.development?
21
+ c.use Faraday::Response::Logger, ActiveSupport::Logger.new($stdout), bodies: true if log_details?
18
22
  c.use Her::Middleware::FirstLevelParseJSON
19
23
 
20
24
  c.use Her::Middleware::SnakeCase
21
25
  # Adapter
22
26
  c.adapter :net_http
27
+
28
+ # HTTP proxy
29
+ c.proxy = Camunda::Workflow.configuration.http_proxy if Camunda::Workflow.configuration.http_proxy
23
30
  end
24
31
  end
25
32
 
@@ -15,12 +15,7 @@ class Camunda::Poller
15
15
  # @param long_polling_duration [Integer] long polling time, default is set to Camunda::Workflow.configuration
16
16
  def self.fetch_and_queue(topics, lock_duration: nil, long_polling_duration: nil)
17
17
  loop do
18
- Camunda::ExternalTask
19
- .fetch_and_lock(topics, lock_duration: lock_duration, long_polling_duration: long_polling_duration).each do |task|
20
- task.queue_task
21
- rescue Camunda::MissingImplementationClass => e
22
- task.failure(e)
23
- end
18
+ Camunda::ExternalTask.fetch_and_queue(topics, lock_duration: lock_duration, long_polling_duration: long_polling_duration)
24
19
  end
25
20
  end
26
21
  end
@@ -23,9 +23,7 @@ class Camunda::ProcessDefinition < Camunda::Model
23
23
  tenant_id ||= Camunda::Workflow.configuration.tenant_id
24
24
 
25
25
  response = post_raw start_path_for_key(key, tenant_id), hash
26
- raise Camunda::ProcessEngineException, response[:parsed_data][:data][:message] unless response[:response].status == 200
27
-
28
- Camunda::ProcessInstance.new response[:parsed_data][:data]
26
+ process_instance_result(response)
29
27
  end
30
28
 
31
29
  # Starts an individual process instance for a process definition. The below example shows how to start a process
@@ -40,9 +38,7 @@ class Camunda::ProcessDefinition < Camunda::Model
40
38
  def start(hash={})
41
39
  hash[:variables] = serialize_variables(hash[:variables]) if hash[:variables]
42
40
  response = self.class.post_raw "process-definition/#{id}/start", hash
43
- raise Camunda::ProcessEngineException, response[:parsed_data][:data][:message] unless response[:response].status == 200
44
-
45
- Camunda::ProcessInstance.new response[:parsed_data][:data]
41
+ self.class.process_instance_result(response)
46
42
  end
47
43
 
48
44
  # Sets path to include tenant_id if a tenant_id is provided with a process definition on deployment.
@@ -51,4 +47,13 @@ class Camunda::ProcessDefinition < Camunda::Model
51
47
  path << "/tenant-id/#{tenant_id}" if tenant_id
52
48
  "#{path}/start"
53
49
  end
50
+
51
+ def self.process_instance_result(response)
52
+ unless response[:response].status == 200
53
+ raise Camunda::ProcessEngineException,
54
+ "#{response[:parsed_data][:data][:message]} HTTP Status: #{response[:response].status}"
55
+ end
56
+
57
+ Camunda::ProcessInstance.new response[:parsed_data][:data]
58
+ end
54
59
  end
data/lib/camunda/task.rb CHANGED
@@ -35,6 +35,24 @@ class Camunda::Task < Camunda::Model
35
35
  end
36
36
  end
37
37
 
38
+ def bpmn_error!(error_code, error_message, vars={})
39
+ self.class
40
+ .post_raw("#{self.class.collection_path}/#{id}/bpmnError", errorCode: error_code, errorMessage: error_message,
41
+ variables: serialize_variables(vars))[:response]
42
+ .tap do |response|
43
+ raise SubmissionError, response.body[:data][:message] unless response.success?
44
+ end
45
+ end
46
+
47
+ def bpmn_escalation!(escalation_code, vars={})
48
+ self.class
49
+ .post_raw("#{self.class.collection_path}/#{id}/bpmnEscalation", escalationCode: escalation_code,
50
+ variables: serialize_variables(vars))[:response]
51
+ .tap do |response|
52
+ raise SubmissionError, response.body[:data][:message] unless response.success?
53
+ end
54
+ end
55
+
38
56
  # Error class when the task cannot be submitted. For instance if the bpmn process expects a variable and the variable
39
57
  # isn't supplied, Camunda will not accept the task
40
58
  class SubmissionError < StandardError
@@ -30,7 +30,7 @@ module Camunda
30
30
  when Float
31
31
  { value: value, type: 'Double' }
32
32
  else
33
- raise ArgumentError, "Not supporting complex types yet"
33
+ raise ArgumentError, "#{value} - Not supporting complex types yet. Variables are #{variables}."
34
34
  end
35
35
  end
36
36
  camelcase_keys(hash)
@@ -41,9 +41,10 @@ module Camunda
41
41
  # @param json [Array,Hash]
42
42
  # @return [Hash] returns hash with camelCase keys
43
43
  def transform_json(json)
44
- if json.is_a?(Array)
44
+ case json
45
+ when Array
45
46
  json.map { |element| transform_json(element) }
46
- elsif json.is_a?(Hash)
47
+ when Hash
47
48
  camelcase_keys(json)
48
49
  else
49
50
  json
@@ -1,5 +1,5 @@
1
1
  module Camunda
2
2
  module Workflow
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
@@ -11,7 +11,7 @@ module Camunda
11
11
  # Implements Configuration class and sets default instance variables. The default variables can be overridden by creating an
12
12
  # initializer file within your rails application and setting the variables like in the example below.
13
13
  # @note if HTTP Basic Auth is used with the Camunda engine, this is where you would set a camunda_user and camunda_password
14
- # using the creditials from a user setup in Camunda Admin.
14
+ # using the credentials from a user setup in Camunda Admin.
15
15
  # @example
16
16
  # 'Camunda::Workflow.configure do |config|
17
17
  # config.engine_url = 'http://localhost:8080'
@@ -64,6 +64,9 @@ module Camunda
64
64
  # Can configure the backtrace silencer
65
65
  # @return [Array<String>] List of backtrace silencer strings which are used to clean incident backtraces
66
66
  attr_accessor :backtrace_silencer_lines
67
+ # Configure an HTTP proxy for all requests to use
68
+ # @return [String] The defined HTTP proxy
69
+ attr_accessor :http_proxy
67
70
 
68
71
  def initialize
69
72
  @engine_url = 'http://localhost:8080'
data/lib/camunda.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/string/inflections.rb'
2
- require 'active_support/core_ext/object/blank.rb'
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'active_support/core_ext/object/blank'
3
3
  require 'her'
4
4
  require 'faraday'
5
5
  require 'faraday_middleware'
@@ -10,6 +10,7 @@ module Camunda
10
10
  class << self
11
11
  # Allows setting the logger to a custom logger
12
12
  attr_writer :logger
13
+
13
14
  # Default is output to the standard output stream.
14
15
  # @return [Object] instance which is used for logging
15
16
  def logger
@@ -27,9 +28,10 @@ module Camunda
27
28
  return if env[:body].blank?
28
29
 
29
30
  json = JSON.parse(env[:body])
30
- if json.is_a?(Array)
31
+ case json
32
+ when Array
31
33
  json.map { |hash| transform_hash!(hash) }
32
- elsif json.is_a?(Hash)
34
+ when Hash
33
35
  transform_hash!(json)
34
36
  end
35
37
  env[:body] = JSON.generate(json)
@@ -35,9 +35,7 @@ module Camunda
35
35
  ignores << '.cfignore' if File.exist?('.cfignore')
36
36
  ignores.each do |file|
37
37
  append_to_file file do
38
- "\n# BPMN Java app\n" +
39
- File.join(java_app_path, 'target') +
40
- "\n"
38
+ "\n# BPMN Java app\n#{File.join(java_app_path, 'target')}\n"
41
39
  end
42
40
  end
43
41
  end
@@ -82,7 +82,7 @@
82
82
  <dependency>
83
83
  <groupId>org.postgresql</groupId>
84
84
  <artifactId>postgresql</artifactId>
85
- <version>42.2.7</version>
85
+ <version>42.2.25</version>
86
86
  </dependency>
87
87
 
88
88
  <dependency>
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camunda-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankur Sethi
8
8
  - Duggan Roberts
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2019-11-22 00:00:00.000000000 Z
@@ -242,7 +242,7 @@ homepage: https://github.com/amalagaura/camunda-workflow
242
242
  licenses:
243
243
  - MIT
244
244
  metadata: {}
245
- post_install_message:
245
+ post_install_message:
246
246
  rdoc_options: []
247
247
  require_paths:
248
248
  - lib
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubygems_version: 3.0.6
261
- signing_key:
261
+ signing_key:
262
262
  specification_version: 4
263
263
  summary: Opinionated Ruby integration with Camunda
264
264
  test_files: []