zeebe_bpmn_rspec 0.3.1 → 0.4.0

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: 6c61752ebec049d8c944c74517f9f36aa57eb89054ca2c16c3dd3e22eeaf83cc
4
- data.tar.gz: 29ef97e9a0901e5b70225425d51df1a4ea27cf15eb75acfdee70c86147c61867
3
+ metadata.gz: 9326bc3b39da887700ba4f953b851cb31bdfcf5c69f66072e32dd8186a230e3e
4
+ data.tar.gz: abf9685a1f5d66fc1704afe29e2664e75ced661f959245689a9bbf9f35925ea4
5
5
  SHA512:
6
- metadata.gz: 38918b2d17281f6cbb36d2263ec6c706ae77ce2b749eb30d9f095613f9f14af61921a9175b76f141019f1f57321b2f33ea794df344aa32062c3d562d73d04051
7
- data.tar.gz: 97180846225b71825b2506d4da6c76e8aa991bdc290adb0e456784fcbe9ab41589a421e55a37d4195f4d235e9cd0ab0ce9a2050e883421840d3d6634c4cfaa4a
6
+ metadata.gz: a63baf2863a6ad3eda3a253c6ca5ae113bf25d082763686aacfcde3b57ece0d73970780a752712b73bd80fab51bc96f41a3ff04cb679c962d29d0cee3b0b4c83
7
+ data.tar.gz: a0f1a2178661ae07958c6c1c3d0b9374a9c790ae3f58ffae418a145eb20b326656c754861c1e57302fc9d662bcd6a60192304cf8feb1f73b64d79611dae37dc3
@@ -1,5 +1,11 @@
1
1
  # zeebe_bpmn_rspec
2
2
 
3
+ ## v0.4.0
4
+ - Add `ttl_ms` option for `publish_message`.
5
+ - Add `update_retries` method to `ActivatedJob` class.
6
+ - Add `set_variables` helper.
7
+ - Add support for `:fetch_variables` option when activating jobs.
8
+
3
9
  ## v0.3.1
4
10
  - Use consistent activate request timeout.
5
11
  - Provide a better error when a job is not activated.
data/README.md CHANGED
@@ -157,6 +157,16 @@ job = activate_job("my_job")
157
157
  job.fail(retries: 1)
158
158
  ```
159
159
 
160
+ #### Update Retries
161
+
162
+ The retries for a job can also be modified using the `update_retries` method:
163
+
164
+ ```ruby
165
+ job = activate_job("my_job")
166
+
167
+ job.update_retries(3)
168
+ ```
169
+
160
170
  #### Throw Error
161
171
 
162
172
  The `and_throw_error` (also aliased as `throw_error`) method can be used to throw an error for a job. The error code is required and an
@@ -219,6 +229,37 @@ publish_message("message_name", correlation_key: expected_value,
219
229
  variables: { foo: "bar" })
220
230
  ```
221
231
 
232
+ The time-to-live (in milliseconds) cna also be specified for a message.
233
+ It defaults to 5000 milliseconds if unspecified.
234
+
235
+ ```ruby
236
+ publish_message("message_name", correlation_key: expected_value, ttl_ms: 1000)
237
+ ```
238
+
239
+ ### Set Variables
240
+
241
+ The `set_variables` method can be used to set variables for a specified
242
+ scope in Zeebe:
243
+
244
+ ```ruby
245
+ # workflow_instance_key is a method that returns the key for the current workflow instance
246
+ set_variables(workflow_instance_key, { foo: "bar" })
247
+ ```
248
+
249
+ An activated job can be used to determine the key for the task that it is associated with:
250
+
251
+ ```ruby
252
+ job = job_with_type("my_type")
253
+ set_variables(job.task_key, { foo: "baz"})
254
+ ```
255
+
256
+ Variables default to being local to the scope on which they are set. This
257
+ can be overridden by specifying the `:local` option:
258
+
259
+ ```ruby
260
+ set_variables(job.task_key, { foo: "baz"}, local: false)
261
+ ```
262
+
222
263
  ### Custom Matchers
223
264
 
224
265
  In addition to the helpers documented above, this gem defines custom RSpec matchers to provide a more typical
@@ -36,6 +36,14 @@ module ZeebeBpmnRspec
36
36
  job.key
37
37
  end
38
38
 
39
+ def retries
40
+ job.retries
41
+ end
42
+
43
+ def task_key
44
+ job.elementInstanceKey
45
+ end
46
+
39
47
  def to_s
40
48
  raw.to_s
41
49
  end
@@ -98,6 +106,13 @@ module ZeebeBpmnRspec
98
106
  end
99
107
  alias complete and_complete
100
108
 
109
+ def update_retries(retries = 1)
110
+ client.update_job_retries(UpdateJobRetriesRequest.new(
111
+ jobKey: job.key,
112
+ retries: retries
113
+ ))
114
+ end
115
+
101
116
  private
102
117
 
103
118
  attr_reader :client, :context
@@ -64,14 +64,15 @@ module ZeebeBpmnRspec
64
64
  @__workflow_instance_key
65
65
  end
66
66
 
67
- def activate_job(type, validate: true)
68
- stream = _zeebe_client.activate_jobs(ActivateJobsRequest.new(
69
- type: type,
70
- worker: "#{type}-#{SecureRandom.hex}",
71
- maxJobsToActivate: 1,
72
- timeout: 1000,
73
- requestTimeout: ZeebeBpmnRspec.activate_request_timeout
74
- ))
67
+ def activate_job(type, fetch_variables: nil, validate: true)
68
+ stream = _zeebe_client.activate_jobs(ActivateJobsRequest.new({
69
+ type: type,
70
+ worker: "#{type}-#{SecureRandom.hex}",
71
+ maxJobsToActivate: 1,
72
+ timeout: 1000,
73
+ fetchVariable: fetch_variables&.then { |v| Array(v) },
74
+ requestTimeout: ZeebeBpmnRspec.activate_request_timeout,
75
+ }.compact))
75
76
 
76
77
  job = nil
77
78
  stream.find { |response| job = response.jobs.first }
@@ -87,20 +88,21 @@ module ZeebeBpmnRspec
87
88
  alias process_job activate_job
88
89
  # TODO: deprecate process_job
89
90
 
90
- def job_with_type(type)
91
- activate_job(type, validate: false)
91
+ def job_with_type(type, fetch_variables: nil)
92
+ activate_job(type, fetch_variables: fetch_variables, validate: false)
92
93
  end
93
94
 
94
- def expect_job_of_type(type)
95
- expect(job_with_type(type))
95
+ def expect_job_of_type(type, fetch_variables: nil)
96
+ expect(job_with_type(type, fetch_variables: fetch_variables))
96
97
  end
97
98
 
98
- def activate_jobs(type, max_jobs: nil)
99
+ def activate_jobs(type, max_jobs: nil, fetch_variables: nil)
99
100
  stream = _zeebe_client.activate_jobs(ActivateJobsRequest.new({
100
101
  type: type,
101
102
  worker: "#{type}-#{SecureRandom.hex}",
102
103
  maxJobsToActivate: max_jobs,
103
104
  timeout: 1000,
105
+ fetchVariable: fetch_variables&.then { |v| Array(v) },
104
106
  requestTimeout: ZeebeBpmnRspec.activate_request_timeout,
105
107
  }.compact))
106
108
 
@@ -118,17 +120,25 @@ module ZeebeBpmnRspec
118
120
  end
119
121
  end
120
122
 
121
- def publish_message(name, correlation_key:, variables: nil)
123
+ def publish_message(name, correlation_key:, variables: nil, ttl_ms: 5000)
122
124
  _zeebe_client.publish_message(PublishMessageRequest.new(
123
125
  {
124
126
  name: name,
125
127
  correlationKey: correlation_key,
126
- timeToLive: 5000,
128
+ timeToLive: ttl_ms,
127
129
  variables: variables&.to_json,
128
130
  }.compact
129
131
  ))
130
132
  end
131
133
 
134
+ def set_variables(key, variables, local: true)
135
+ _zeebe_client.set_variables(SetVariablesRequest.new(
136
+ elementInstanceKey: key,
137
+ variables: variables.to_json,
138
+ local: local
139
+ ))
140
+ end
141
+
132
142
  def reset_zeebe!
133
143
  @__workflow_instance_key = nil
134
144
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZeebeBpmnRspec
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeebe_bpmn_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler