cloudmunda 0.1.1 → 0.1.2

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: '0882dcb50d23ad283984404e67f589a28d39a08c19ec44b9c2ca00659386962e'
4
- data.tar.gz: 7d03f8ddd3c6cc8ba8a464e64e84a14234a791540f947a25cb94dd36fd5bc8c1
3
+ metadata.gz: 6de3487afc170ba54716321f6b3c1c473c0156eb34b583978d99c6a75c25ff2b
4
+ data.tar.gz: 764de78b6e60f42bb9fa06bab3e709579bdf4d4f51eb4217fcc395dbf4f06d05
5
5
  SHA512:
6
- metadata.gz: 1aa60b038071944496032564eb73a21c3344211ab4339cc77d9d74de6ecaf7814e31eb69fafada0cd6f25432f9e4a85f2cf9003edf209735605986f9c5c26f9b
7
- data.tar.gz: 5e5d47130dc95f8d98a12facaf4dc8830cded1f3420e3b96df838d5730c01339dd0187177d9f5d92c6c1ac175b67d647530dc497383686eda2d46a16cba57355
6
+ metadata.gz: 3e81773f5488f23358fd4a71a41a8c046f1bc744532b780648dd5f8eece35ec404f58031a8f7e09764b6a6f2740f9ed4e74a0f40047a945da7ff2ae51eeb762e
7
+ data.tar.gz: 0de770be1f7cd89b60906041c87b43677cdab0dc2de082c44036abdc28f17d2a74a0a2d0cac2ec0b79b0af4f45c0f51a3a0711bc9138616f9701d0c5dd89ccad
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2021-02-25
4
+ - Add class method `runs_in_development` to Cloudmunda::Worker. This way you can run only specific jobs in development.
5
+
3
6
  ## [0.1.1] - 2021-12-16
4
7
 
5
8
  - Camunda Cloud Access Token Creation
@@ -8,5 +11,4 @@
8
11
 
9
12
  ## [0.1.0] - 2021-12-16
10
13
 
11
- - Initial release
12
- _
14
+ - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudmunda (0.1.1)
4
+ cloudmunda (0.1.2)
5
5
  concurrent-ruby (~> 1.0)
6
6
  rest-client (~> 2.0)
7
7
  zeebe-client (~> 0.16)
@@ -98,7 +98,7 @@ GEM
98
98
  method_source (1.0.0)
99
99
  mime-types (3.4.1)
100
100
  mime-types-data (~> 3.2015)
101
- mime-types-data (3.2021.1115)
101
+ mime-types-data (3.2022.0105)
102
102
  mini_mime (1.1.2)
103
103
  minitest (5.14.4)
104
104
  netrc (0.11.0)
@@ -189,7 +189,7 @@ GEM
189
189
  websocket-driver (0.7.5)
190
190
  websocket-extensions (>= 0.1.0)
191
191
  websocket-extensions (0.1.5)
192
- zeebe-client (0.16.0)
192
+ zeebe-client (0.16.1)
193
193
  grpc (~> 1.32)
194
194
  zeitwerk (2.5.1)
195
195
 
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Cloudmunda
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cloudmunda`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This Ruby gem makes it easier to connect your Ruby (on Rails) app with Camunda Cloud. 🎉
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The following is included:
6
+ - Ruby workers for Zeebe
7
+ - API wrapper for Camunda Cloud
8
+ - graphQL wrapper Usertasks
9
+
10
+ To use this library you need:
11
+
12
+ * a [Camunda Cloud Account](https://accounts.cloud.camunda.io/signup)
13
+ * your [Camunda client connection credentials](https://docs.camunda.io/docs/guides/getting-started/setup-client-connection-credentials/)
6
14
 
7
15
  ## Installation
8
16
 
@@ -20,18 +28,159 @@ Or install it yourself as:
20
28
 
21
29
  $ gem install cloudmunda
22
30
 
23
- ## Usage
31
+ ### Rails applications
32
+
33
+ If you're using this gem with a rails application, you could create a `config/initializers/cloudmunda.rb` file and add
34
+ the following:
35
+
36
+ ```ruby
37
+ Cloudmunda.configure do |config|
38
+ config.env = ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
39
+ config.logger = Logger.new($stdout)
40
+ config.timeout = 30
41
+ config.client_id = ENV['ZEEBE_CLIENT_ID']
42
+ config.client_secret = ENV['ZEEBE_CLIENT_SECRET']
43
+ config.zeebe_url = ENV['ZEEBE_URL']
44
+ config.auth_url = ENV['ZEEBE_AUTHORIZATION_SERVER_URL']
45
+ config.audience = ENV['ZEEBE_AUDIENCE']
46
+ config.graphql_url = ENV['GRAPHQL_URL']
47
+ end
48
+ ```
49
+
50
+ The values listed above are the default values that you can override.
51
+
52
+ ## Example Usage
53
+
54
+ This section will explain the usage as you were using a Rails application, but steps should be very similar within plain
55
+ Ruby apps or any other frameworks out there. Feel free to create an issue or PR if additional items are needed.
56
+
57
+ The idea of the example is that when a certain webhook comes in, a Slack message is sent. This might look like a bit
58
+ of overhead to use a business process engine for this, but it's just to show how the library works. Since we're
59
+ communicating with Slack, you'd need a Slack workspace. You can also change the code in the example to send an email or
60
+ just write something in the logs.
61
+
62
+ You can find all the code [here](https://github.com/lienvdsteen/cloudmunda-demo).
63
+
64
+ ### Add Slack and Cloudmunda gem
65
+ In your Gemfile add this line
66
+
67
+ ```ruby
68
+ gem 'cloudmunda'
69
+ gem 'slack-ruby-client' # this is just for our example
70
+ ```
71
+
72
+ Then run
73
+
74
+ ```shell
75
+ bundle install
76
+ ```
77
+
78
+ As said above, create a initializer file so that whenever you are interacting with them gem you have the right settings set:
79
+
80
+ ```shell
81
+ touch config/initializers/cloudmunda.rb
82
+ touch config/initializers/slack.rb # again, this is just for our example
83
+ ```
84
+
85
+ Then open the `cloudmunda.rb` file and copy the following in it:
24
86
 
25
87
  ```ruby
26
88
  Cloudmunda.configure do |config|
27
89
  config.env = ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
28
- config.require = '.'
90
+ config.logger = Logger.new($stdout)
29
91
  config.timeout = 30
92
+ config.client_id = ENV['ZEEBE_CLIENT_ID']
93
+ config.client_secret = ENV['ZEEBE_CLIENT_SECRET']
30
94
  config.zeebe_url = ENV['ZEEBE_URL']
31
95
  config.auth_url = ENV['ZEEBE_AUTHORIZATION_SERVER_URL']
96
+ config.audience = ENV['ZEEBE_AUDIENCE']
97
+ config.graphql_url = ENV['GRAPHQL_URL']
98
+ end
99
+ ```
100
+
101
+ Then open the `slack.rb` file and copy the following
102
+
103
+ ```ruby
104
+ Slack.configure do |config|
105
+ config.token = ENV['SLACK_OAUTH_TOKEN']
106
+ end
107
+ ```
108
+
109
+ Note: this assumes you're using ENV variables, you can of course edit this to use something like `Settings.key` or
110
+ how you prefer it. Just make sure not to publish your secrets.
111
+
112
+ ### Deploy the diagram to your Camunda Cloud cluster
113
+ You can either import the [bpmn model example](/diagrams/demo.bpmn) as a diagram in your Camunda Cloud and
114
+ use the UI to deploy or you can start a console (`rails console`) and deploy the diagram with the gem.
115
+
116
+ ```ruby
117
+ Cloudmunda.client.deploy_process(processes: [name: "demo", definition: File.read('diagrams/demo.bpmn')])
118
+ ```
119
+
120
+ ### Create a worker
121
+
122
+ In `app/jobs` create a new file `demo_worker_job.rb` and copy paste the following:
123
+
124
+ ```ruby
125
+ class DemoWorkerJob
126
+ include ::Cloudmunda::Worker
127
+
128
+ type 'webhook-slack-announce'
129
+ max_jobs_to_activate 20
130
+ poll_interval 1
131
+ timeout 45
132
+
133
+ attr_reader :variables
134
+
135
+ def process(job)
136
+ slack_client.chat_postMessage(channel: '#general', text: 'a message', as_user: true)
137
+ end
138
+
139
+ private
140
+
141
+ def slack_client
142
+ @slack_client ||= ::Slack::Web::Client.new
143
+ end
32
144
  end
33
145
  ```
34
146
 
147
+ ### Setup the "webhook"
148
+ Add the following to your `routes.rb` file `get 'webhook/received', to: 'webhook#received'` and then create a file
149
+ `webhooks_controller.rb` in the controllers directory and copy paste the following:
150
+
151
+ ```ruby
152
+ class WebhookController < ApplicationController
153
+ def received
154
+ Cloudmunda.client.create_process_instance(
155
+ bpmnProcessId: 'cloudmunda-demo',
156
+ version: 1,
157
+ variables: {text: "hello"}.to_json
158
+ )
159
+
160
+ head :ok
161
+ end
162
+ end
163
+ ```
164
+
165
+ #### Run everything
166
+
167
+ Now everything should be able to execute. Lets start your rails server and then in another terminal tab run the following:
168
+
169
+ ````ruby
170
+ bundle exec cloudmunda \
171
+ --require .
172
+ --client-id $ZEEBE_CLIENT_ID \
173
+ --client-secret $ZEEBE_CLIENT_SECRET \
174
+ --zeebe-url $ZEEBE_URL \
175
+ --zeebe-auth-url $ZEEBE_AUTHORIZATION_SERVER_URL \
176
+ --audience $ZEEBE_AUDIENCE
177
+ ````
178
+
179
+ Then navigate to `localhost:3000/webhook/received`, what will happen is the following:
180
+ 1. It goes to the `received` endpoint in the `WebhookController`
181
+ 2. Here a new process instance is created on Camunda Cloud
182
+ 3. This will then trigger the next step in the diagram, which is the service task
183
+ 4. Through the grpc protocol our worker is linked with this service task and will be executed.
35
184
 
36
185
  ## Development
37
186
 
@@ -42,6 +191,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
42
191
  ## Contributing
43
192
 
44
193
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cloudmunda. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cloudmunda/blob/main/CODE_OF_CONDUCT.md).
194
+ Looking for:
195
+ - unit testing: currently nothing is tested
196
+ - additional API endpoints
197
+ - additional graphQL endpoints
198
+ - general improvements
45
199
 
46
200
  ## License
47
201
 
@@ -50,3 +204,9 @@ The gem is available as open source under the terms of the [MIT License](https:/
50
204
  ## Code of Conduct
51
205
 
52
206
  Everyone interacting in the Cloudmunda project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cloudmunda/blob/main/CODE_OF_CONDUCT.md).
207
+
208
+ ## Credits
209
+
210
+ This gem is build on top of what [@gottfrois](https://github.com/gottfrois/) had build in his [beez](https://github.com/gottfrois/beez)
211
+ gem. Everything in this gem related to the Ruby workers is a taken from that gem. 👏 Cloudmunda would **not** be
212
+ possible without this.
@@ -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>
@@ -8,6 +8,12 @@ module Cloudmunda
8
8
 
9
9
  def start
10
10
  @processors = workers.map do |worker_class|
11
+ if ::Cloudmunda.env == 'development' && !worker_class.get_runs_in_development
12
+ logger.info "Not starting a processor for worker #{worker_class.get_type} as it doesn't run in development."
13
+ next
14
+ end
15
+
16
+ logger.info "Starting a processor for worker #{worker_class.get_type}"
11
17
  processor = ::Cloudmunda::Processor.new(worker_class: worker_class)
12
18
  processor.start
13
19
  end
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Cloudmunda
4
4
  module Worker
5
- attr_accessor :client, :type, :max_jobs_to_activate, :poll_interval, :timeout, :variables
5
+ attr_accessor :client, :type, :max_jobs_to_activate, :poll_interval, :timeout, :variables, :runs_in_development
6
6
 
7
7
  def self.included(base)
8
8
  base.extend(ClassMethods)
@@ -150,6 +150,27 @@ module Cloudmunda
150
150
  @variables.to_a
151
151
  end
152
152
 
153
+ # Sets if this service task runs in development mode or not.
154
+ #
155
+ # @example
156
+ # class MyWorker
157
+ # include ::Cloudmunda::Worker
158
+ # runs_in_development true
159
+ # end
160
+ #
161
+ # @param [Boolean] runs_in_development
162
+ # @return [Boolean]
163
+ def runs_in_development(runs_in_development)
164
+ @runs_in_development = runs_in_development
165
+ end
166
+
167
+ # Returns if this service task should run in development mode.
168
+ #
169
+ # @return [Boolean]
170
+ def get_runs_in_development
171
+ @runs_in_development || false
172
+ end
173
+
153
174
  # Returns the worker's name.
154
175
  #
155
176
  # @return [String]
@@ -23,7 +23,7 @@ module Cloudmunda
23
23
  @env = ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
24
24
  @logger = Logger.new($stdout)
25
25
  @require = "."
26
- @timeout = 30
26
+ @timeout = @env == 'development' ? 5 : 30
27
27
  @zeebe_url = ENV['ZEEBE_URL']
28
28
  @auth_url = ENV['ZEEBE_AUTHORIZATION_SERVER_URL']
29
29
  @client_id = ENV['ZEEBE_CLIENT_ID']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudmunda
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudmunda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lien Van Den Steen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-16 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -71,6 +71,7 @@ files:
71
71
  - Rakefile
72
72
  - bin/console
73
73
  - bin/setup
74
+ - diagrams/demo.bpmn
74
75
  - exe/cloudmunda
75
76
  - lib/cloudmunda.rb
76
77
  - lib/cloudmunda/api.rb