beez 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/beez/client.rb CHANGED
@@ -2,7 +2,6 @@ require 'zeebe/client'
2
2
 
3
3
  module Beez
4
4
  class Client
5
-
6
5
  attr_reader :client
7
6
 
8
7
  def initialize(url: ::Beez.config.zeebe_url, opts: :this_channel_is_insecure)
@@ -10,73 +9,87 @@ module Beez
10
9
  end
11
10
 
12
11
  def activate_jobs(params = {})
13
- run(:activate_jobs,
12
+ run(
13
+ :activate_jobs,
14
14
  ::Zeebe::Client::GatewayProtocol::ActivateJobsRequest.new(params)
15
15
  )
16
16
  end
17
17
 
18
18
  def cancel_workflow_instance(params = {})
19
- run(:cancel_workflow_instance,
19
+ run(
20
+ :cancel_workflow_instance,
20
21
  ::Zeebe::Client::GatewayProtocol::CancelWorkflowInstanceRequest.new(params)
21
22
  )
22
23
  end
23
24
 
24
25
  def complete_job(params = {})
25
- run(:complete_job,
26
+ run(
27
+ :complete_job,
26
28
  ::Zeebe::Client::GatewayProtocol::CompleteJobRequest.new(params)
27
29
  )
28
30
  end
29
31
 
30
- def create_workflow_instance(params = {})
31
- run(:create_workflow_instance,
32
- ::Zeebe::Client::GatewayProtocol::CreateWorkflowInstanceRequest.new(params)
32
+ def create_process_instance(params = {})
33
+ run(
34
+ :create_process_instance,
35
+ ::Zeebe::Client::GatewayProtocol::CreateProcessInstanceRequest.new(params)
33
36
  )
34
37
  end
35
38
 
36
- def deploy_workflow(params = {})
37
- run(:deploy_workflow,
38
- ::Zeebe::Client::GatewayProtocol::DeployWorkflowRequest.new(params)
39
+ def deploy_process(params = {})
40
+ run(
41
+ :deploy_process,
42
+ ::Zeebe::Client::GatewayProtocol::DeployProcessRequest.new(params)
39
43
  )
40
44
  end
41
45
 
42
46
  def fail_job(params = {})
43
- run(:fail_job,
47
+ run(
48
+ :fail_job,
44
49
  ::Zeebe::Client::GatewayProtocol::FailJobRequest.new(params)
45
50
  )
46
51
  end
47
52
 
48
53
  def throw_error(params = {})
49
- run(:throw_error,
54
+ run(
55
+ :throw_error,
50
56
  ::Zeebe::Client::GatewayProtocol::ThrowErrorRequest.new(params)
51
57
  )
52
58
  end
53
59
 
54
60
  def publish_message(params = {})
55
- run(:publish_message,
61
+ run(
62
+ :publish_message,
56
63
  ::Zeebe::Client::GatewayProtocol::PublishMessageRequest.new(params)
57
64
  )
58
65
  end
59
66
 
60
67
  def resolve_incident(params = {})
61
- run(:resolve_incident,
68
+ run(
69
+ :resolve_incident,
62
70
  ::Zeebe::Client::GatewayProtocol::ResolveIncidentRequest.new(params)
63
71
  )
64
72
  end
65
73
 
74
+ # rubocop:disable Naming/AccessorMethodName
66
75
  def set_variables(params = {})
67
- run(:set_variables,
76
+ run(
77
+ :set_variables,
68
78
  ::Zeebe::Client::GatewayProtocol::SetVariablesRequest.new(params)
69
79
  )
70
80
  end
81
+ # rubocop:enable Naming/AccessorMethodName
71
82
 
72
83
  def topology(params = {})
73
- run(:topology,
84
+ run(
85
+ :topology,
74
86
  ::Zeebe::Client::GatewayProtocol::TopologyRequest.new(params)
75
87
  )
76
88
  end
77
89
 
78
90
  def update_job_retries(params = {})
79
- run(:update_job_retries,
91
+ run(
92
+ :update_job_retries,
80
93
  ::Zeebe::Client::GatewayProtocol::UpdateJobRetriesRequest.new(params)
81
94
  )
82
95
  end
@@ -85,9 +98,9 @@ module Beez
85
98
 
86
99
  def run(method, params = {})
87
100
  client.public_send(method, params)
88
- rescue ::GRPC::Unavailable => exception
89
- logger.error exception.message
90
- raise exception
101
+ rescue ::GRPC::Unavailable => e
102
+ logger.error e.message
103
+ raise e
91
104
  end
92
105
 
93
106
  def logger
@@ -1,12 +1,11 @@
1
1
  module Beez
2
2
  class Configuration
3
-
4
3
  attr_accessor :env, :logger, :require, :timeout, :zeebe_url
5
4
 
6
5
  def initialize
7
- @env = ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
6
+ @env = ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
8
7
  @logger = Logger.new($stdout)
9
- @require = "."
8
+ @require = '.'
10
9
  @timeout = 30
11
10
  @zeebe_url = ENV['ZEEBE_URL'] || 'localhost:26500'
12
11
  end
data/lib/beez/launcher.rb CHANGED
@@ -2,7 +2,6 @@ require 'beez/supervisor'
2
2
 
3
3
  module Beez
4
4
  class Launcher
5
-
6
5
  attr_reader :supervisor
7
6
 
8
7
  def initialize
@@ -1,9 +1,8 @@
1
1
  module Beez
2
2
  class Processor
3
-
4
3
  attr_reader :client, :worker_class, :busy_count, :timer
5
4
 
6
- def initialize(client: ::Beez.client, worker_class:)
5
+ def initialize(worker_class:, client: ::Beez.client)
7
6
  @client = client
8
7
  @worker_class = worker_class
9
8
  @busy_count = ::Concurrent::AtomicFixnum.new(0)
@@ -45,18 +44,39 @@ module Beez
45
44
  end
46
45
  end
47
46
 
47
+ # rubocop:disable Metrics/AbcSize
48
+ # rubocop:disable Metrics/MethodLength
48
49
  def process(job)
49
50
  worker = worker_class.new(client)
50
51
  begin
51
- worker.process(job)
52
- worker.complete_job(job)
53
- rescue => exception
54
- worker.fail_job(job, reason: exception.message)
55
- raise exception
52
+ logger.info "class=#{worker_class} jid=#{job.key} Start processing #{job.type}"
53
+
54
+ duration =
55
+ measure_duration do
56
+ worker.process(job)
57
+ worker.complete_job(job)
58
+ end
59
+
60
+ logger.info "class=#{worker_class} jid=#{job.key} duration=#{duration} Done processing #{job.type}"
61
+ rescue StandardError => e
62
+ logger.info "class=#{worker_class} jid=#{job.key} Failed processing #{job.type}: #{e.message}"
63
+
64
+ worker.fail_job(job, reason: e.message)
65
+ raise e
56
66
  ensure
57
67
  busy_count.decrement
58
68
  end
59
69
  end
70
+ # rubocop:enable Metrics/AbcSize
71
+ # rubocop:enable Metrics/MethodLength
72
+
73
+ def measure_duration
74
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
75
+ yield
76
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
77
+
78
+ ending - starting
79
+ end
60
80
 
61
81
  def activate_jobs_request
62
82
  client.activate_jobs(
@@ -64,7 +84,7 @@ module Beez
64
84
  worker: worker_name,
65
85
  timeout: worker_timeout * 1000,
66
86
  maxJobsToActivate: max_jobs_to_activate,
67
- fetchVariable: worker_variables_to_fetch,
87
+ fetchVariable: worker_variables_to_fetch
68
88
  )
69
89
  end
70
90
 
data/lib/beez/rails.rb CHANGED
@@ -5,10 +5,8 @@ module Beez
5
5
  @app = app
6
6
  end
7
7
 
8
- def call
9
- @app.reloader.wrap do
10
- yield
11
- end
8
+ def call(&block)
9
+ @app.reloader.wrap(&block)
12
10
  end
13
11
 
14
12
  def inspect
@@ -2,7 +2,6 @@ require 'beez/processor'
2
2
 
3
3
  module Beez
4
4
  class Supervisor
5
-
6
5
  def initialize
7
6
  @processors = []
8
7
  end
@@ -15,7 +14,7 @@ module Beez
15
14
  end
16
15
 
17
16
  def quiet
18
- logger.info "Terminating workers"
17
+ logger.info 'Terminating workers'
19
18
  @processors.each(&:stop)
20
19
  end
21
20
 
data/lib/beez/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Beez
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/beez/worker.rb CHANGED
@@ -14,21 +14,19 @@ module Beez
14
14
  end
15
15
 
16
16
  def complete_job(job, variables: {})
17
- logger.info "Completed processing job #{job.type} #{job.key}"
18
17
  client.complete_job(
19
18
  jobKey: job.key,
20
- variables: Hash(variables).to_json,
19
+ variables: Hash(variables).to_json
21
20
  )
22
21
  end
23
22
 
24
- def fail_job(job, reason: "")
25
- logger.error "Failed processing job #{job.type} #{job.key}: #{reason}"
23
+ def fail_job(job, reason: '')
26
24
  client.fail_job(
27
25
  jobKey: job.key,
28
26
  retries: job.retries - 1,
29
- errorMessage: reason,
27
+ errorMessage: reason
30
28
  )
31
- rescue => e
29
+ rescue StandardError => e
32
30
  logger.error e.message
33
31
  end
34
32
 
@@ -155,7 +153,7 @@ module Beez
155
153
  # @return [String]
156
154
  def get_name
157
155
  name = self.name.gsub(/::/, ':')
158
- name.gsub!(/([^A-Z:])([A-Z])/) { "#{$1}_#{$2}" }
156
+ name.gsub!(/([^A-Z:])([A-Z])/) { "#{Regexp.last_match(1)}_#{Regexp.last_match(2)}" }
159
157
  name.downcase
160
158
  end
161
159
  end
data/lib/beez.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'concurrent'
2
2
 
3
3
  require 'beez/configurable'
4
- require 'beez/Loggable'
4
+ require 'beez/loggable'
5
5
  require 'beez/client'
6
6
  require 'beez/worker'
7
7
  require 'beez/version'
@@ -10,10 +10,8 @@ module Beez
10
10
  extend ::Beez::Configurable
11
11
  extend ::Beez::Loggable
12
12
 
13
- # class Error < StandardError; end
14
-
15
13
  def self.register_worker(worker)
16
- self.workers << worker
14
+ workers << worker
17
15
  end
18
16
 
19
17
  def self.workers
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beez
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2022-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: zeebe-client
14
+ name: concurrent-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.7'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: concurrent-ruby
28
+ name: zeebe-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '0.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
83
125
  description: Simple, efficient ruby workers for Zeebe business processes.
84
126
  email:
85
127
  - pierrelouis.gottfrois@gmail.com
@@ -90,7 +132,9 @@ extra_rdoc_files: []
90
132
  files:
91
133
  - ".gitignore"
92
134
  - ".rspec"
135
+ - ".rubocop.yml"
93
136
  - ".ruby-version"
137
+ - ".travis.yml"
94
138
  - CHANGELOG.md
95
139
  - CODE_OF_CONDUCT.md
96
140
  - Gemfile
@@ -98,6 +142,9 @@ files:
98
142
  - LICENSE.txt
99
143
  - README.md
100
144
  - Rakefile
145
+ - assets/images/bee.png
146
+ - assets/images/order-process.png
147
+ - assets/images/zeebe-operate.jpeg
101
148
  - beez.gemspec
102
149
  - bin/console
103
150
  - bin/setup
@@ -132,14 +179,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
179
  requirements:
133
180
  - - ">="
134
181
  - !ruby/object:Gem::Version
135
- version: 2.3.0
182
+ version: 2.6.0
136
183
  required_rubygems_version: !ruby/object:Gem::Requirement
137
184
  requirements:
138
185
  - - ">="
139
186
  - !ruby/object:Gem::Version
140
187
  version: '0'
141
188
  requirements: []
142
- rubygems_version: 3.0.8
189
+ rubygems_version: 3.3.7
143
190
  signing_key:
144
191
  specification_version: 4
145
192
  summary: Simple, efficient ruby workers for Zeebe business processes.