camunda-workflow 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/camunda.rb +6 -4
- data/lib/camunda/external_task.rb +20 -1
- data/lib/camunda/model.rb +8 -1
- data/lib/camunda/poller.rb +1 -6
- data/lib/camunda/process_definition.rb +11 -6
- data/lib/camunda/variable_serialization.rb +3 -2
- data/lib/camunda/workflow.rb +4 -1
- data/lib/camunda/workflow/version.rb +1 -1
- data/lib/generators/camunda/spring_boot/spring_boot_generator.rb +1 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59fd3142d352f68570b4fc0ad558e0853035f733127e11fd384e3b1749103423
|
4
|
+
data.tar.gz: 20d53613e7b3d4d81cc3221d9f4bfce1cec3f80d017448cf05bc29e19f26297a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf2d0f7ac7bb1ced5bf8d8f840fecf238d9202788c283da01794c1857926a4882fa60a065c3ca2cda094c0eed81afff09592202aeaf84ee28d298e67c2169c9
|
7
|
+
data.tar.gz: 81f51922568cda9e16826715f8fd209859a2a3ab14bf74c3767eeb2b1e60655830e301e795478f76fe9d45af22c3b1650d4a7afd3e37a89629946b6c478d7890
|
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
|
-
|
156
|
+
### Add to your Gemfile
|
157
157
|
```ruby
|
158
158
|
gem 'camunda-workflow'
|
159
159
|
```
|
@@ -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
|
data/lib/camunda.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'active_support/core_ext/string/inflections
|
2
|
-
require 'active_support/core_ext/object/blank
|
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
|
-
|
31
|
+
case json
|
32
|
+
when Array
|
31
33
|
json.map { |hash| transform_hash!(hash) }
|
32
|
-
|
34
|
+
when Hash
|
33
35
|
transform_hash!(json)
|
34
36
|
end
|
35
37
|
env[:body] = JSON.generate(json)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'active_support/core_ext/string/inflections
|
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(
|
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
|
|
data/lib/camunda/poller.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
@@ -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
|
-
|
44
|
+
case json
|
45
|
+
when Array
|
45
46
|
json.map { |element| transform_json(element) }
|
46
|
-
|
47
|
+
when Hash
|
47
48
|
camelcase_keys(json)
|
48
49
|
else
|
49
50
|
json
|
data/lib/camunda/workflow.rb
CHANGED
@@ -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
|
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'
|
@@ -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
|
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.
|
4
|
+
version: 0.3.0
|
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: []
|