cloudmunda 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -7
- data/.rubocop_todo.yml +39 -0
- data/CHANGELOG.md +10 -2
- data/Gemfile +5 -5
- data/Gemfile.lock +129 -110
- data/README.md +164 -4
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/diagrams/demo.bpmn +47 -0
- data/exe/cloudmunda +8 -5
- data/lib/cloudmunda/api/access_token.rb +4 -4
- data/lib/cloudmunda/api/client.rb +2 -2
- data/lib/cloudmunda/api/o_auth_resource.rb +1 -5
- data/lib/cloudmunda/api.rb +2 -1
- data/lib/cloudmunda/cli/launcher.rb +2 -1
- data/lib/cloudmunda/cli/processor.rb +8 -7
- data/lib/cloudmunda/cli/supervisor.rb +11 -3
- data/lib/cloudmunda/cli/worker.rb +30 -7
- data/lib/cloudmunda/cli.rb +29 -30
- data/lib/cloudmunda/configuration.rb +8 -5
- data/lib/cloudmunda/graphql/client.rb +2 -1
- data/lib/cloudmunda/graphql.rb +3 -1
- data/lib/cloudmunda/loggable.rb +2 -0
- data/lib/cloudmunda/version.rb +1 -1
- data/lib/cloudmunda/zeebe/client.rb +18 -29
- data/lib/cloudmunda/zeebe.rb +3 -1
- data/lib/cloudmunda.rb +2 -2
- metadata +15 -16
data/diagrams/demo.bpmn
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0rbumvm" targetNamespace="http://bpmn.io/schema/bpmn" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.2.0">
|
3
|
+
<bpmn:process id="cloudmunda-demo" name="cloudmunda-demo" isExecutable="true">
|
4
|
+
<bpmn:startEvent id="StartEvent_1" name="Webhook received">
|
5
|
+
<bpmn:outgoing>Flow_0easrsr</bpmn:outgoing>
|
6
|
+
</bpmn:startEvent>
|
7
|
+
<bpmn:sequenceFlow id="Flow_0easrsr" sourceRef="StartEvent_1" targetRef="Activity_0le34m7" />
|
8
|
+
<bpmn:endEvent id="Event_0a948ov" name="Webhook processed">
|
9
|
+
<bpmn:incoming>Flow_1g4bjdg</bpmn:incoming>
|
10
|
+
</bpmn:endEvent>
|
11
|
+
<bpmn:sequenceFlow id="Flow_1g4bjdg" sourceRef="Activity_0le34m7" targetRef="Event_0a948ov" />
|
12
|
+
<bpmn:serviceTask id="Activity_0le34m7" name="Send slack message to announce">
|
13
|
+
<bpmn:extensionElements>
|
14
|
+
<zeebe:taskDefinition type="webhook-slack-announce" />
|
15
|
+
</bpmn:extensionElements>
|
16
|
+
<bpmn:incoming>Flow_0easrsr</bpmn:incoming>
|
17
|
+
<bpmn:outgoing>Flow_1g4bjdg</bpmn:outgoing>
|
18
|
+
</bpmn:serviceTask>
|
19
|
+
</bpmn:process>
|
20
|
+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
21
|
+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="cloudmunda-demo">
|
22
|
+
<bpmndi:BPMNEdge id="Flow_0easrsr_di" bpmnElement="Flow_0easrsr">
|
23
|
+
<di:waypoint x="215" y="97" />
|
24
|
+
<di:waypoint x="270" y="97" />
|
25
|
+
</bpmndi:BPMNEdge>
|
26
|
+
<bpmndi:BPMNEdge id="Flow_1g4bjdg_di" bpmnElement="Flow_1g4bjdg">
|
27
|
+
<di:waypoint x="370" y="97" />
|
28
|
+
<di:waypoint x="432" y="97" />
|
29
|
+
</bpmndi:BPMNEdge>
|
30
|
+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
31
|
+
<dc:Bounds x="179" y="79" width="36" height="36" />
|
32
|
+
<bpmndi:BPMNLabel>
|
33
|
+
<dc:Bounds x="174" y="122" width="47" height="27" />
|
34
|
+
</bpmndi:BPMNLabel>
|
35
|
+
</bpmndi:BPMNShape>
|
36
|
+
<bpmndi:BPMNShape id="Event_0a948ov_di" bpmnElement="Event_0a948ov">
|
37
|
+
<dc:Bounds x="432" y="79" width="36" height="36" />
|
38
|
+
<bpmndi:BPMNLabel>
|
39
|
+
<dc:Bounds x="425" y="122" width="51" height="27" />
|
40
|
+
</bpmndi:BPMNLabel>
|
41
|
+
</bpmndi:BPMNShape>
|
42
|
+
<bpmndi:BPMNShape id="Activity_1qerp1u_di" bpmnElement="Activity_0le34m7">
|
43
|
+
<dc:Bounds x="270" y="57" width="100" height="80" />
|
44
|
+
</bpmndi:BPMNShape>
|
45
|
+
</bpmndi:BPMNPlane>
|
46
|
+
</bpmndi:BPMNDiagram>
|
47
|
+
</bpmn:definitions>
|
data/exe/cloudmunda
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'cloudmunda/cli'
|
4
6
|
|
5
7
|
begin
|
6
8
|
cli = ::Cloudmunda::CLI.instance
|
7
9
|
cli.parse
|
8
10
|
cli.run
|
9
|
-
rescue => e
|
11
|
+
rescue StandardError => e
|
10
12
|
raise e if $DEBUG
|
11
|
-
|
12
|
-
|
13
|
+
|
14
|
+
warn e.message
|
15
|
+
warn e.backtrace.join("\n")
|
13
16
|
exit 1
|
14
17
|
end
|
@@ -6,10 +6,10 @@ module Cloudmunda
|
|
6
6
|
def self.create(audience_url: Cloudmunda.audience)
|
7
7
|
uri = Cloudmunda.auth_url
|
8
8
|
payload = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
grant_type: 'client_credentials',
|
10
|
+
audience: audience_url,
|
11
|
+
client_id: Cloudmunda.client_id,
|
12
|
+
client_secret: Cloudmunda.client_secret
|
13
13
|
}
|
14
14
|
|
15
15
|
create_by_uri(uri: uri, payload: payload)
|
@@ -15,7 +15,7 @@ module Cloudmunda
|
|
15
15
|
|
16
16
|
def self.headers
|
17
17
|
{
|
18
|
-
authorization: "Basic
|
18
|
+
authorization: "Basic #{Base64.strict_encode64("#{Cloudmunda.client_id}:#{Cloudmunda.client_secret}")}"
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -26,4 +26,4 @@ module Cloudmunda
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
@@ -7,13 +7,9 @@ module Cloudmunda
|
|
7
7
|
class OAuthResource < OpenStruct
|
8
8
|
def self.create_by_uri(uri:, payload:)
|
9
9
|
raw_item = Cloudmunda::API::Client.post(uri, payload)
|
10
|
-
raw_item = {} if raw_item ==
|
10
|
+
raw_item = {} if raw_item == ''
|
11
11
|
new(raw_item)
|
12
12
|
end
|
13
|
-
|
14
|
-
def initialize(raw)
|
15
|
-
super(raw)
|
16
|
-
end
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
data/lib/cloudmunda/api.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Cloudmunda
|
2
4
|
class Processor
|
3
|
-
|
4
5
|
attr_reader :client, :worker_class, :busy_count, :timer
|
5
6
|
|
6
|
-
def initialize(client: ::Cloudmunda.client
|
7
|
+
def initialize(worker_class:, client: ::Cloudmunda.client)
|
7
8
|
@client = client
|
8
9
|
@worker_class = worker_class
|
9
10
|
@busy_count = ::Concurrent::AtomicFixnum.new(0)
|
@@ -54,11 +55,11 @@ module Cloudmunda
|
|
54
55
|
worker.complete_job(job)
|
55
56
|
|
56
57
|
logger.info "class=#{worker_class} jid=#{job.key} Done processing #{job.type}"
|
57
|
-
rescue =>
|
58
|
-
logger.info "class=#{worker_class} jid=#{job.key} Failed processing #{job.type}: #{
|
58
|
+
rescue StandardError => e
|
59
|
+
logger.info "class=#{worker_class} jid=#{job.key} Failed processing #{job.type}: #{e.message}"
|
59
60
|
|
60
|
-
worker.fail_job(job, reason:
|
61
|
-
raise
|
61
|
+
worker.fail_job(job, reason: e.message)
|
62
|
+
raise e
|
62
63
|
ensure
|
63
64
|
busy_count.decrement
|
64
65
|
end
|
@@ -70,7 +71,7 @@ module Cloudmunda
|
|
70
71
|
worker: worker_name,
|
71
72
|
timeout: worker_timeout * 1000,
|
72
73
|
maxJobsToActivate: max_jobs_to_activate,
|
73
|
-
fetchVariable: worker_variables_to_fetch
|
74
|
+
fetchVariable: worker_variables_to_fetch
|
74
75
|
)
|
75
76
|
end
|
76
77
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'processor'
|
2
4
|
|
3
5
|
module Cloudmunda
|
@@ -7,14 +9,20 @@ module Cloudmunda
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def start
|
10
|
-
|
12
|
+
workers.each do |worker_class|
|
13
|
+
if ::Cloudmunda.env == 'development' && !worker_class.get_runs_in_development
|
14
|
+
logger.info "Not starting a processor for worker #{worker_class.get_type} as it doesn't run in development."
|
15
|
+
next
|
16
|
+
end
|
17
|
+
|
18
|
+
logger.info "Starting a processor for worker #{worker_class.get_type}"
|
11
19
|
processor = ::Cloudmunda::Processor.new(worker_class: worker_class)
|
12
|
-
processor.start
|
20
|
+
@processors << processor.start
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
16
24
|
def quiet
|
17
|
-
logger.info
|
25
|
+
logger.info 'Terminating workers'
|
18
26
|
@processors.each(&:stop)
|
19
27
|
end
|
20
28
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
|
3
5
|
module Cloudmunda
|
4
6
|
module Worker
|
5
|
-
attr_accessor :client, :type, :max_jobs_to_activate, :poll_interval, :timeout, :variables
|
7
|
+
attr_accessor :client, :type, :max_jobs_to_activate, :poll_interval, :timeout, :variables, :runs_in_development
|
6
8
|
|
7
9
|
def self.included(base)
|
8
10
|
base.extend(ClassMethods)
|
@@ -17,18 +19,18 @@ module Cloudmunda
|
|
17
19
|
logger.info "Completed processing job #{job.type} #{job.key}"
|
18
20
|
client.complete_job(
|
19
21
|
jobKey: job.key,
|
20
|
-
variables: Hash(variables).to_json
|
22
|
+
variables: Hash(variables).to_json
|
21
23
|
)
|
22
24
|
end
|
23
25
|
|
24
|
-
def fail_job(job, reason:
|
26
|
+
def fail_job(job, reason: '')
|
25
27
|
logger.error "Failed processing job #{job.type} #{job.key}: #{reason}"
|
26
28
|
client.fail_job(
|
27
29
|
jobKey: job.key,
|
28
30
|
retries: job.retries - 1,
|
29
|
-
errorMessage: reason
|
31
|
+
errorMessage: reason
|
30
32
|
)
|
31
|
-
rescue => e
|
33
|
+
rescue StandardError => e
|
32
34
|
logger.error e.message
|
33
35
|
end
|
34
36
|
|
@@ -55,7 +57,7 @@ module Cloudmunda
|
|
55
57
|
#
|
56
58
|
# @return [String]
|
57
59
|
def get_type
|
58
|
-
@type
|
60
|
+
get_runs_in_development ? "#{@type}-dev" : @type
|
59
61
|
end
|
60
62
|
|
61
63
|
# Sets the maximum number of jobs to send to the worker for processing at once.
|
@@ -150,12 +152,33 @@ module Cloudmunda
|
|
150
152
|
@variables.to_a
|
151
153
|
end
|
152
154
|
|
155
|
+
# Sets if this service task runs in development mode or not.
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# class MyWorker
|
159
|
+
# include ::Cloudmunda::Worker
|
160
|
+
# runs_in_development true
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# @param [Boolean] runs_in_development
|
164
|
+
# @return [Boolean]
|
165
|
+
def runs_in_development(runs_in_development)
|
166
|
+
@runs_in_development = runs_in_development
|
167
|
+
end
|
168
|
+
|
169
|
+
# Returns if this service task should run in development mode.
|
170
|
+
#
|
171
|
+
# @return [Boolean]
|
172
|
+
def get_runs_in_development
|
173
|
+
@runs_in_development || false
|
174
|
+
end
|
175
|
+
|
153
176
|
# Returns the worker's name.
|
154
177
|
#
|
155
178
|
# @return [String]
|
156
179
|
def get_name
|
157
180
|
name = self.name.gsub(/::/, ':')
|
158
|
-
name.gsub!(/([^A-Z:])([A-Z])/) { "#{
|
181
|
+
name.gsub!(/([^A-Z:])([A-Z])/) { "#{Regexp.last_match(1)}_#{Regexp.last_match(2)}" }
|
159
182
|
name.downcase
|
160
183
|
end
|
161
184
|
end
|
data/lib/cloudmunda/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'singleton'
|
2
4
|
require 'optparse'
|
3
5
|
require 'fileutils'
|
@@ -40,46 +42,47 @@ module Cloudmunda
|
|
40
42
|
|
41
43
|
def option_parser
|
42
44
|
OptionParser.new.tap do |p|
|
43
|
-
p.on
|
45
|
+
p.on '-e', '--env ENV', 'Application environment' do |arg|
|
44
46
|
config.env = arg
|
45
47
|
end
|
46
48
|
|
47
|
-
p.on
|
49
|
+
p.on '-i', '--client-id CLIENT_ID', 'Client ID' do |arg|
|
48
50
|
config.client_id = arg
|
49
51
|
end
|
50
52
|
|
51
|
-
p.on
|
53
|
+
p.on '-r', '--require [PATH|DIR]', 'Location of Rails application with workers or file to require' do |arg|
|
52
54
|
if !File.exist?(arg) ||
|
53
|
-
|
55
|
+
(File.directory?(arg) && !File.exist?("#{arg}/config/application.rb"))
|
54
56
|
raise ArgumentError, "#{arg} is not a ruby file nor a rails application"
|
55
57
|
else
|
56
58
|
config.require = arg
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
p.on
|
62
|
+
p.on '-s', '--client-secret CLIENT_SECRET', 'Client Secret' do |arg|
|
61
63
|
config.client_secret = arg
|
62
64
|
end
|
63
65
|
|
64
|
-
p.on
|
66
|
+
p.on '-u', '--zeebe-url ZEEBE_URL', 'Zeebe URL' do |arg|
|
65
67
|
config.zeebe_url = arg
|
66
68
|
end
|
67
69
|
|
68
|
-
p.on
|
70
|
+
p.on '-U', '--zeebe-auth-url ZEEBE_AUTH_URL', 'Zeebe Authorization Server URL' do |arg|
|
69
71
|
config.auth_url = arg
|
70
72
|
end
|
71
73
|
|
72
|
-
p.on
|
74
|
+
p.on '-a', '--audience URL', 'Zeebe Audience' do |arg|
|
73
75
|
config.audience = arg
|
74
76
|
end
|
75
77
|
|
76
|
-
p.on
|
78
|
+
p.on '-T', '--use-access-token STRING', 'Zeebe Audience' do |arg|
|
77
79
|
config.use_access_token = arg.to_s.downcase == 'true'
|
78
80
|
end
|
79
81
|
|
80
|
-
p.on
|
82
|
+
p.on '-t', '--timeout NUM', 'Shutdown timeout' do |arg|
|
81
83
|
timeout = Integer(arg)
|
82
|
-
raise ArgumentError,
|
84
|
+
raise ArgumentError, 'timeout must be a positive integer' if timeout <= 0
|
85
|
+
|
83
86
|
config.timeout = timeout
|
84
87
|
end
|
85
88
|
|
@@ -87,13 +90,13 @@ module Cloudmunda
|
|
87
90
|
# ::Cloudmuna.logger.level = ::Logger::DEBUG
|
88
91
|
# end
|
89
92
|
|
90
|
-
p.on
|
93
|
+
p.on '-V', '--version', 'Print version and exit' do |_arg|
|
91
94
|
puts "Cloudmunda #{::Cloudmunda::VERSION}"
|
92
95
|
exit(0)
|
93
96
|
end
|
94
97
|
|
95
|
-
p.banner =
|
96
|
-
p.on_tail
|
98
|
+
p.banner = 'Usage: cloudmunda [options]'
|
99
|
+
p.on_tail '-h', '--help', 'Show help' do
|
97
100
|
puts p
|
98
101
|
|
99
102
|
exit(1)
|
@@ -102,18 +105,16 @@ module Cloudmunda
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def boot
|
105
|
-
ENV[
|
108
|
+
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = config.env
|
106
109
|
|
107
110
|
if File.directory?(config.require)
|
108
111
|
require 'rails'
|
109
|
-
if ::Rails::VERSION::MAJOR < 6
|
110
|
-
raise "Cloudmunda does not supports this version of Rails"
|
111
|
-
else
|
112
|
-
require File.expand_path("#{config.require}/config/environment.rb")
|
113
|
-
Dir[Rails.root.join('app/jobs/**/*.rb')].each { |f| require f }
|
112
|
+
raise 'Cloudmunda does not supports this version of Rails' if ::Rails::VERSION::MAJOR < 6
|
114
113
|
|
115
|
-
|
116
|
-
|
114
|
+
require File.expand_path("#{config.require}/config/environment.rb")
|
115
|
+
Dir[Rails.root.join('app/jobs/**/*.rb')].sort.each { |f| require f }
|
116
|
+
|
117
|
+
logger.info "Booted Rails #{::Rails.version} application in #{config.env} environment"
|
117
118
|
else
|
118
119
|
require config.require
|
119
120
|
end
|
@@ -122,21 +123,19 @@ module Cloudmunda
|
|
122
123
|
def launch(self_read)
|
123
124
|
@launcher = ::Cloudmunda::Launcher.new
|
124
125
|
|
125
|
-
if config.env ==
|
126
|
-
logger.info "Starting processing, hit Ctrl-C to stop"
|
127
|
-
end
|
126
|
+
logger.info 'Starting processing, hit Ctrl-C to stop' if config.env == 'development' && $stdout.tty?
|
128
127
|
|
129
128
|
begin
|
130
129
|
launcher.start
|
131
130
|
|
132
|
-
while readable_io = IO.select([self_read])
|
131
|
+
while (readable_io = IO.select([self_read]))
|
133
132
|
signal = readable_io.first[0].gets.strip
|
134
133
|
handle_signal(signal)
|
135
134
|
end
|
136
135
|
rescue Interrupt
|
137
|
-
logger.info
|
136
|
+
logger.info 'Shutting down'
|
138
137
|
launcher.stop
|
139
|
-
logger.info
|
138
|
+
logger.info 'Bye!'
|
140
139
|
|
141
140
|
exit(0)
|
142
141
|
end
|
@@ -153,8 +152,8 @@ module Cloudmunda
|
|
153
152
|
|
154
153
|
def signal_handlers
|
155
154
|
{
|
156
|
-
|
157
|
-
|
155
|
+
'INT' => ->(_cli) { raise Interrupt },
|
156
|
+
'TERM' => ->(_cli) { raise Interrupt }
|
158
157
|
}
|
159
158
|
end
|
160
159
|
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Cloudmunda
|
2
4
|
module Configuration
|
3
|
-
VALID_OPTIONS_KEYS = %i[env require logger timeout zeebe_url auth_url client_id client_secret audience
|
5
|
+
VALID_OPTIONS_KEYS = %i[env require logger timeout zeebe_url auth_url client_id client_secret audience
|
6
|
+
graphql_url].freeze
|
4
7
|
attr_accessor(*VALID_OPTIONS_KEYS)
|
5
8
|
|
6
9
|
# Sets all configuration options to their default values when this module is extended.
|
@@ -20,10 +23,10 @@ module Cloudmunda
|
|
20
23
|
|
21
24
|
# Resets all configuration options to the defaults.
|
22
25
|
def reset
|
23
|
-
@env = ENV[
|
26
|
+
@env = ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
24
27
|
@logger = Logger.new($stdout)
|
25
|
-
@require =
|
26
|
-
@timeout = 30
|
28
|
+
@require = '.'
|
29
|
+
@timeout = @env == 'development' ? 5 : 30
|
27
30
|
@zeebe_url = ENV['ZEEBE_URL']
|
28
31
|
@auth_url = ENV['ZEEBE_AUTHORIZATION_SERVER_URL']
|
29
32
|
@client_id = ENV['ZEEBE_CLIENT_ID']
|
@@ -32,4 +35,4 @@ module Cloudmunda
|
|
32
35
|
@graphql_url = ENV['GRAPHQL_URL']
|
33
36
|
end
|
34
37
|
end
|
35
|
-
end
|
38
|
+
end
|
@@ -14,8 +14,9 @@ module Cloudmunda
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.headers
|
17
|
+
access_token = Cloudmunda::API::AccessToken.create(audience_url: 'tasklist.camunda.io').access_token
|
17
18
|
{
|
18
|
-
authorization: "Bearer "
|
19
|
+
authorization: "Bearer #{access_token}"
|
19
20
|
}
|
20
21
|
end
|
21
22
|
|
data/lib/cloudmunda/graphql.rb
CHANGED
data/lib/cloudmunda/loggable.rb
CHANGED
data/lib/cloudmunda/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'zeebe/client'
|
2
4
|
|
3
5
|
module Cloudmunda
|
4
6
|
module Zeebe
|
5
7
|
class Client
|
6
|
-
|
7
8
|
attr_reader :client
|
8
9
|
|
9
10
|
def initialize(url: ::Cloudmunda.zeebe_url)
|
@@ -12,83 +13,71 @@ module Cloudmunda
|
|
12
13
|
|
13
14
|
def activate_jobs(params = {})
|
14
15
|
run(:activate_jobs,
|
15
|
-
|
16
|
-
)
|
16
|
+
::Zeebe::Client::GatewayProtocol::ActivateJobsRequest.new(params))
|
17
17
|
end
|
18
18
|
|
19
19
|
def cancel_workflow_instance(params = {})
|
20
20
|
run(:cancel_workflow_instance,
|
21
|
-
|
22
|
-
)
|
21
|
+
::Zeebe::Client::GatewayProtocol::CancelWorkflowInstanceRequest.new(params))
|
23
22
|
end
|
24
23
|
|
25
24
|
def complete_job(params = {})
|
26
25
|
run(:complete_job,
|
27
|
-
|
28
|
-
)
|
26
|
+
::Zeebe::Client::GatewayProtocol::CompleteJobRequest.new(params))
|
29
27
|
end
|
30
28
|
|
31
29
|
def create_process_instance(params = {})
|
32
30
|
run(:create_process_instance,
|
33
|
-
|
34
|
-
)
|
31
|
+
::Zeebe::Client::GatewayProtocol::CreateProcessInstanceRequest.new(params))
|
35
32
|
end
|
36
33
|
|
37
34
|
def deploy_process(params = {})
|
38
35
|
run(:deploy_process,
|
39
|
-
|
40
|
-
)
|
36
|
+
::Zeebe::Client::GatewayProtocol::DeployProcessRequest.new(params))
|
41
37
|
end
|
42
38
|
|
43
39
|
def fail_job(params = {})
|
44
40
|
run(:fail_job,
|
45
|
-
|
46
|
-
)
|
41
|
+
::Zeebe::Client::GatewayProtocol::FailJobRequest.new(params))
|
47
42
|
end
|
48
43
|
|
49
44
|
def throw_error(params = {})
|
50
45
|
run(:throw_error,
|
51
|
-
|
52
|
-
)
|
46
|
+
::Zeebe::Client::GatewayProtocol::ThrowErrorRequest.new(params))
|
53
47
|
end
|
54
48
|
|
55
49
|
def publish_message(params = {})
|
56
50
|
run(:publish_message,
|
57
|
-
|
58
|
-
)
|
51
|
+
::Zeebe::Client::GatewayProtocol::PublishMessageRequest.new(params))
|
59
52
|
end
|
60
53
|
|
61
54
|
def resolve_incident(params = {})
|
62
55
|
run(:resolve_incident,
|
63
|
-
|
64
|
-
)
|
56
|
+
::Zeebe::Client::GatewayProtocol::ResolveIncidentRequest.new(params))
|
65
57
|
end
|
66
58
|
|
67
59
|
def set_variables(params = {})
|
68
60
|
run(:set_variables,
|
69
|
-
|
70
|
-
)
|
61
|
+
::Zeebe::Client::GatewayProtocol::SetVariablesRequest.new(params))
|
71
62
|
end
|
72
63
|
|
73
64
|
def topology(params = {})
|
74
65
|
run(:topology,
|
75
|
-
|
76
|
-
)
|
66
|
+
::Zeebe::Client::GatewayProtocol::TopologyRequest.new(params))
|
77
67
|
end
|
78
68
|
|
79
69
|
def update_job_retries(params = {})
|
80
70
|
run(:update_job_retries,
|
81
|
-
|
82
|
-
)
|
71
|
+
::Zeebe::Client::GatewayProtocol::UpdateJobRetriesRequest.new(params))
|
83
72
|
end
|
84
73
|
|
85
74
|
private
|
86
75
|
|
87
76
|
def run(method, params = {})
|
88
77
|
client.public_send(method, params)
|
89
|
-
rescue ::GRPC::Unavailable =>
|
90
|
-
logger.error
|
91
|
-
raise
|
78
|
+
rescue ::GRPC::Unavailable => e
|
79
|
+
logger.error e.message
|
80
|
+
raise e
|
92
81
|
end
|
93
82
|
|
94
83
|
def logger
|
@@ -97,7 +86,7 @@ module Cloudmunda
|
|
97
86
|
|
98
87
|
def authentication_headers
|
99
88
|
token = Cloudmunda::API::AccessToken.create
|
100
|
-
channel_creds = GRPC::Core::ChannelCredentials.new
|
89
|
+
channel_creds = GRPC::Core::ChannelCredentials.new
|
101
90
|
auth_proc = proc { { 'authorization' => "Bearer #{token.access_token}" } }
|
102
91
|
call_creds = GRPC::Core::CallCredentials.new(auth_proc)
|
103
92
|
channel_creds.compose(call_creds)
|
data/lib/cloudmunda/zeebe.rb
CHANGED
data/lib/cloudmunda.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'concurrent'
|
4
4
|
|
5
|
-
require_relative
|
5
|
+
require_relative 'cloudmunda/version'
|
6
6
|
require_relative 'cloudmunda/loggable'
|
7
7
|
require_relative 'cloudmunda/cli/worker'
|
8
8
|
require_relative 'cloudmunda/configuration'
|
@@ -19,7 +19,7 @@ module Cloudmunda
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.register_worker(worker)
|
22
|
-
|
22
|
+
workers << worker
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.workers
|