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.
- checksums.yaml +4 -4
- data/.rubocop.yml +24 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +27 -2
- data/Gemfile +3 -3
- data/Gemfile.lock +135 -105
- data/README.md +138 -68
- data/Rakefile +2 -2
- data/assets/images/bee.png +0 -0
- data/assets/images/order-process.png +0 -0
- data/assets/images/zeebe-operate.jpeg +0 -0
- data/beez.gemspec +23 -20
- data/bin/console +3 -3
- data/examples/workers.rb +12 -13
- data/exe/beez +6 -5
- data/lib/beez/cli.rb +35 -30
- data/lib/beez/client.rb +33 -20
- data/lib/beez/configuration.rb +2 -3
- data/lib/beez/launcher.rb +0 -1
- data/lib/beez/processor.rb +28 -8
- data/lib/beez/rails.rb +2 -4
- data/lib/beez/supervisor.rb +1 -2
- data/lib/beez/version.rb +1 -1
- data/lib/beez/worker.rb +5 -7
- data/lib/beez.rb +2 -4
- metadata +59 -12
data/README.md
CHANGED
@@ -1,76 +1,104 @@
|
|
1
|
-
|
1
|
+
<h1 align="center">
|
2
|
+
<br>
|
3
|
+
<a href="https://github.com/gottfrois/beez"><img src="https://github.com/gottfrois/beez/blob/master/assets/images/bee.png?raw=true" alt="Beez" width="200"></a>
|
4
|
+
<br>
|
5
|
+
Beez
|
6
|
+
</h1>
|
2
7
|
|
3
|
-
|
8
|
+
<h4 align="center">
|
9
|
+
Simple, efficient ruby workers for <a href="https://zeebe.io/" target="_blank">Zeebe</a>.
|
10
|
+
</h4>
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
12
|
+
<p align="center">
|
13
|
+
<a href="https://badge.fury.io/rb/beez"><img src="https://badge.fury.io/rb/beez.svg" alt="Gem Version" height="18"></a>
|
14
|
+
</p>
|
8
15
|
|
9
|
-
|
16
|
+
<p align="center">
|
17
|
+
<a href="#features-">Features</a> •
|
18
|
+
<a href="#disclaimer-%EF%B8%8F">Disclaimer</a> •
|
19
|
+
<a href="#getting-started-">Getting Started</a> •
|
20
|
+
<a href="#usage-">Usage</a> •
|
21
|
+
<a href="#configuration-">Configuration</a> •
|
22
|
+
<a href="#example-">Example</a> •
|
23
|
+
<a href="#license-">License</a> •
|
24
|
+
<a href="#credits-">Credits</a>
|
25
|
+
</p>
|
26
|
+
<br>
|
10
27
|
|
11
|
-
|
12
|
-
|
13
|
-
|
28
|
+
<p align="center">
|
29
|
+
<img src="https://github.com/gottfrois/beez/blob/master/assets/images/zeebe-operate.jpeg?raw=true" alt="Zeebe Operate">
|
30
|
+
<em>Beez lets you consume Zeebe workflows like this one!</em>
|
31
|
+
</p>
|
14
32
|
|
15
|
-
|
16
|
-
love the concepts behind Zeebe, this is why I bootstraped this library.
|
33
|
+
## Features ✨
|
17
34
|
|
18
|
-
|
35
|
+
- Beez integrates with [Zeebe](https://zeebe.io/), a free and source-available workflow engine for microservices orchestration
|
36
|
+
- Beez integrates with you Rails application
|
37
|
+
- Beez runs your workers asynchronously
|
38
|
+
- Beez automatically marks your jobs as failures uppon Ruby exceptions
|
39
|
+
- Beez has very few dependencies
|
19
40
|
|
20
|
-
##
|
41
|
+
## Disclaimer ⚠️
|
21
42
|
|
22
|
-
|
43
|
+
- Beez is currently a pre-release
|
44
|
+
- Beez has currently **not being tested in production**
|
45
|
+
- Beez is currently lacking unit tests, any help is welcome!
|
23
46
|
|
24
|
-
|
25
|
-
gem 'beez'
|
26
|
-
```
|
47
|
+
## Getting Started 🎓
|
27
48
|
|
28
|
-
|
49
|
+
These instructions will help you get started with [Zeebe](https://zeebe.io/)
|
50
|
+
and Beez. [Zeebe](https://zeebe.io/) already provides an extensive [documentation](https://docs.zeebe.io/)
|
51
|
+
I highly suggest you to check it out before.
|
29
52
|
|
30
|
-
|
53
|
+
### Prerequisites ☔️
|
31
54
|
|
32
|
-
|
55
|
+
- You need [Zeebe up and running](https://docs.zeebe.io/introduction/install.html)
|
56
|
+
- Ruby >= 2.5 & < 2.7
|
57
|
+
- Rails >= 4 (optional)
|
33
58
|
|
34
|
-
|
59
|
+
### How It Works ⚙️
|
35
60
|
|
36
|
-
|
61
|
+
Workflows are flowchart-like blueprints that define the orchestration of tasks.
|
62
|
+
Every task represents a piece of business logic such that the ordered execution
|
63
|
+
produces a meaningful result.
|
37
64
|
|
38
|
-
|
39
|
-
|
65
|
+
Beez lets you define job workers as Ruby classes which is your implementation of
|
66
|
+
the business logic required to complete a task.
|
40
67
|
|
41
|
-
|
68
|
+
Running a workflow then requires two steps:
|
42
69
|
|
43
|
-
|
70
|
+
1. Submitting the workflow to Zeebe
|
71
|
+
2. Creating job workers that can request jobs from Zeebe and complete them
|
44
72
|
|
45
|
-
###
|
73
|
+
### Installation ☕️
|
46
74
|
|
47
|
-
|
75
|
+
Add this line to your application's Gemfile:
|
48
76
|
|
49
77
|
```ruby
|
50
|
-
|
51
|
-
|
78
|
+
gem 'beez', '~> 0.1'
|
79
|
+
```
|
52
80
|
|
53
|
-
|
81
|
+
And then execute:
|
54
82
|
|
55
|
-
|
56
|
-
# do something
|
57
|
-
end
|
58
|
-
end
|
83
|
+
$ bundle
|
59
84
|
|
60
|
-
|
61
|
-
include ::Beez::Worker
|
85
|
+
Or install it yourself as:
|
62
86
|
|
63
|
-
|
87
|
+
$ gem install beez
|
64
88
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
89
|
+
### Usage 🎆
|
90
|
+
|
91
|
+
Let's start by creating some workers. In your Rails application, those would be
|
92
|
+
defined under `app/jobs` or `app/workers` for example.
|
69
93
|
|
70
|
-
|
94
|
+
```ruby
|
95
|
+
class MyWorker
|
71
96
|
include ::Beez::Worker
|
72
97
|
|
73
|
-
type "
|
98
|
+
type "service-task-name"
|
99
|
+
max_jobs_to_activate 5 # optional, default to 1
|
100
|
+
poll_interval 1 # optional, default to 5
|
101
|
+
timeout 30 # optional, default to 30
|
74
102
|
|
75
103
|
def process(job)
|
76
104
|
# do something
|
@@ -78,9 +106,17 @@ class ShipWithoutInsuranceWorker
|
|
78
106
|
end
|
79
107
|
```
|
80
108
|
|
81
|
-
|
109
|
+
Each worker automatically polls for new jobs at `poll_interval` interval. They
|
110
|
+
are configured to accepts a `max_jobs_to_activate` jobs at the same time.
|
111
|
+
Workers have exactly `timeout` seconds to process the job before the broker
|
112
|
+
consider it as expired and schedule it to another worker.
|
113
|
+
|
114
|
+
The `process` instance method receives a `job` instance which holds the job's
|
115
|
+
attributes such as the `variables` the job received. You can get the complete
|
116
|
+
list of attributes available [here](https://github.com/zeebe-io/zeebe-client-ruby/blob/master/lib/zeebe/client/proto/gateway_pb.rb#L20-L32)
|
82
117
|
|
83
|
-
|
118
|
+
Assuming you have [Zeebe](https://zeebe.io/) up and running, simply start Beez
|
119
|
+
from the root of your Rails application:
|
84
120
|
|
85
121
|
```sh
|
86
122
|
bundle exec beez
|
@@ -88,35 +124,69 @@ bundle exec beez
|
|
88
124
|
|
89
125
|
That's it.
|
90
126
|
|
91
|
-
###
|
127
|
+
### Configuration 🔧
|
128
|
+
|
129
|
+
Beez comes configured with global sane defaults but you can always
|
130
|
+
overrides them using either env variables in some cases or the `configure`
|
131
|
+
block:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
# Here are the global defaults already configured for you
|
135
|
+
Beez.configure do |config|
|
136
|
+
config.env = ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
137
|
+
config.logger = Logger.new($stdout)
|
138
|
+
config.require = "."
|
139
|
+
config.timeout = 30
|
140
|
+
config.zeebe_url = ENV['ZEEBE_URL'] || 'localhost:26500'
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
### Example 📘
|
92
145
|
|
93
|
-
|
94
|
-
|
146
|
+
Let's get the full picture by deploying a dummy [Order Process](https://github.com/gottfrois/beez/blob/master/bpmn/order-process.bpmn) workflow to Zeebe and
|
147
|
+
define simple workers as plain Ruby objects.
|
148
|
+
|
149
|
+

|
150
|
+
|
151
|
+
1. Start Zeebe and Zeebe Operate:
|
95
152
|
|
96
153
|
```sh
|
97
|
-
|
154
|
+
git clone https://github.com/camunda-cloud/camunda-cloud-get-started/
|
155
|
+
docker-compose up
|
98
156
|
```
|
99
157
|
|
100
|
-
|
158
|
+
2. Head to [http://localhost:8080](http://localhost:8080)
|
101
159
|
|
102
|
-
|
160
|
+
- Login: `demo`
|
161
|
+
- Password: `demo`
|
103
162
|
|
104
|
-
|
163
|
+
3. Start Beez using our example workers located at [`examples/workers.rb`](https://github.com/gottfrois/beez/blob/master/examples/workers.rb):
|
105
164
|
|
106
|
-
```
|
107
|
-
|
165
|
+
```sh
|
166
|
+
beez --timeout 5 --require ./examples/workers.rb
|
167
|
+
```
|
108
168
|
|
109
|
-
|
110
|
-
client.deploy_workflow(name: "order-process", type: :BPMN, definition: File.read('./bnmn/order-process.bpmn'))
|
169
|
+
4. Start an `irb` session:
|
111
170
|
|
112
|
-
|
113
|
-
|
171
|
+
```sh
|
172
|
+
irb -r beez
|
173
|
+
```
|
174
|
+
|
175
|
+
5. Interact with Zeebe directly from the gem:
|
114
176
|
|
115
|
-
|
116
|
-
|
177
|
+
```ruby
|
178
|
+
2.6.6 :001 > # Deploy a process to Zeebe
|
179
|
+
2.6.6 :002 > Beez.client.deploy_process(processes: [name: "order-process", definition: File.read('/path/to/beez/bpmn/order-process.bpmn')])
|
180
|
+
2.6.6 :003 > # Create a new instance of this process
|
181
|
+
2.6.6 :004 > Beez.client.create_process_instance(bpmnProcessId: "order-process", version: 1, variables: { orderId: "1234", orderValue: 94 }.to_json)
|
182
|
+
2.6.6 :005 > # Watch Beez automatically executing the first task!
|
183
|
+
2.6.6 :006 > # Publish a business message to simulate a payment received event
|
184
|
+
2.6.6 :007 > Beez.client.publish_message(name: "payment-received", correlationKey: "1234")
|
117
185
|
```
|
118
186
|
|
119
|
-
|
187
|
+
That's it!
|
188
|
+
|
189
|
+
_Check out all the available commands in [`lib/beez/client.rb`](https://github.com/gottfrois/beez/blob/master/lib/beez/client.rb)._
|
120
190
|
|
121
191
|
## Development
|
122
192
|
|
@@ -124,16 +194,16 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
124
194
|
|
125
195
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
126
196
|
|
127
|
-
## Contributing
|
197
|
+
## Contributing 🤝
|
128
198
|
|
129
199
|
Bug reports and pull requests are welcome on GitHub at https://github.com/gottfrois/beez.
|
130
200
|
|
131
|
-
## License
|
201
|
+
## License 📜
|
132
202
|
|
133
203
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
134
204
|
|
135
|
-
##
|
205
|
+
## Credits 👏
|
136
206
|
|
137
|
-
|
138
|
-
|
139
|
-
|
207
|
+
- The [Sidekiq](https://github.com/mperham/sidekiq) authors and contributors for
|
208
|
+
their inspirational codebase which helped me to build this gem
|
209
|
+
- [Logo vector created by raftel - www.freepik.com](https://www.freepik.com/free-photos-vectors/logo)
|
data/Rakefile
CHANGED
Binary file
|
Binary file
|
Binary file
|
data/beez.gemspec
CHANGED
@@ -1,36 +1,39 @@
|
|
1
1
|
require_relative 'lib/beez/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
4
|
+
spec.name = 'beez'
|
5
5
|
spec.version = Beez::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
6
|
+
spec.authors = ['Pierre-Louis Gottfrois']
|
7
|
+
spec.email = ['pierrelouis.gottfrois@gmail.com']
|
8
8
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
9
|
+
spec.summary = 'Simple, efficient ruby workers for Zeebe business processes.'
|
10
|
+
spec.description = 'Simple, efficient ruby workers for Zeebe business processes.'
|
11
|
+
spec.homepage = 'https://github.com/gottfrois/beez'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
14
14
|
|
15
|
-
spec.metadata[
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
16
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/gottfrois/beez'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/gottfrois/beez/CHANGELOG.md'
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
25
|
end
|
26
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
30
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.0'
|
31
|
+
spec.add_dependency 'zeebe-client', '~> 0.7'
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency 'bundler'
|
34
|
+
spec.add_development_dependency 'pry'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
37
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
|
38
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
|
36
39
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'beez'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "beez"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/examples/workers.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'beez'
|
2
2
|
|
3
3
|
module Workers
|
4
4
|
class InitiatePaymentWorker
|
5
5
|
include ::Beez::Worker
|
6
6
|
|
7
|
-
type
|
8
|
-
max_jobs_to_activate
|
7
|
+
type 'initiate-payment'
|
8
|
+
max_jobs_to_activate 20
|
9
9
|
poll_interval 1
|
10
10
|
timeout 30
|
11
11
|
|
12
|
-
def process(
|
13
|
-
rand(
|
14
|
-
logger.info "Processing job #{job.type} #{job.key} by waiting #{i}s"
|
12
|
+
def process(_job)
|
13
|
+
rand(5).times do |_i|
|
15
14
|
sleep 1
|
16
15
|
end
|
17
16
|
end
|
@@ -20,13 +19,12 @@ module Workers
|
|
20
19
|
class ShipWithInsuranceWorker
|
21
20
|
include ::Beez::Worker
|
22
21
|
|
23
|
-
type
|
22
|
+
type 'ship-with-insurance'
|
24
23
|
max_jobs_to_activate 5
|
25
24
|
poll_interval 1
|
26
25
|
|
27
|
-
def process(
|
28
|
-
rand(
|
29
|
-
logger.info "Processing job #{job.type} #{job.key} by waiting #{i}s"
|
26
|
+
def process(_job)
|
27
|
+
rand(5).times do |_i|
|
30
28
|
sleep 1
|
31
29
|
end
|
32
30
|
end
|
@@ -35,13 +33,14 @@ module Workers
|
|
35
33
|
class ShipWithoutInsuranceWorker
|
36
34
|
include ::Beez::Worker
|
37
35
|
|
38
|
-
type
|
36
|
+
type 'ship-without-insurance'
|
39
37
|
max_jobs_to_activate 5
|
40
38
|
poll_interval 1
|
41
39
|
|
42
40
|
def process(job)
|
43
|
-
|
44
|
-
|
41
|
+
raise ArgumentError, "orderValue can't be < 10" if JSON.parse(job.variables)['orderValue'].to_i < 10
|
42
|
+
|
43
|
+
rand(5).times do |_i|
|
45
44
|
sleep 1
|
46
45
|
end
|
47
46
|
end
|
data/exe/beez
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'beez/cli'
|
4
4
|
|
5
5
|
begin
|
6
6
|
cli = ::Beez::CLI.instance
|
7
7
|
cli.parse
|
8
8
|
cli.run
|
9
|
-
rescue => e
|
9
|
+
rescue StandardError => e
|
10
10
|
raise e if $DEBUG
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
warn e.message
|
13
|
+
warn e.backtrace.join("\n")
|
13
14
|
exit 1
|
14
15
|
end
|
data/lib/beez/cli.rb
CHANGED
@@ -38,83 +38,88 @@ module Beez
|
|
38
38
|
option_parser.parse!(argv)
|
39
39
|
end
|
40
40
|
|
41
|
+
# rubocop:disable Metrics/AbcSize
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
43
|
+
# rubocop:disable Metrics/BlockLength
|
41
44
|
def option_parser
|
42
45
|
OptionParser.new.tap do |p|
|
43
|
-
p.on
|
46
|
+
p.on '-e', '--env ENV', 'Application environment' do |arg|
|
44
47
|
config.env = arg
|
45
48
|
end
|
46
49
|
|
47
|
-
p.on
|
50
|
+
p.on '-r', '--require [PATH|DIR]', 'Location of Rails application with workers or file to require' do |arg|
|
48
51
|
if !File.exist?(arg) ||
|
49
|
-
|
52
|
+
(File.directory?(arg) && !File.exist?("#{arg}/config/application.rb"))
|
50
53
|
raise ArgumentError, "#{arg} is not a ruby file nor a rails application"
|
51
54
|
else
|
52
55
|
config.require = arg
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
p.on
|
59
|
+
p.on '-t', '--timeout NUM', 'Shutdown timeout' do |arg|
|
57
60
|
timeout = Integer(arg)
|
58
|
-
raise ArgumentError,
|
61
|
+
raise ArgumentError, 'timeout must be a positive integer' if timeout <= 0
|
62
|
+
|
59
63
|
config.timeout = timeout
|
60
64
|
end
|
61
65
|
|
62
|
-
p.on
|
66
|
+
p.on '-v', '--verbose', 'Print more verbose output' do |_arg|
|
63
67
|
::Beez.logger.level = ::Logger::DEBUG
|
64
68
|
end
|
65
69
|
|
66
|
-
p.on
|
70
|
+
p.on '-V', '--version', 'Print version and exit' do |_arg|
|
67
71
|
puts "Beez #{::Beez::VERSION}"
|
68
72
|
exit(0)
|
69
73
|
end
|
70
74
|
|
71
|
-
p.banner =
|
72
|
-
p.on_tail
|
75
|
+
p.banner = 'Usage: beez [options]'
|
76
|
+
p.on_tail '-h', '--help', 'Show help' do
|
73
77
|
puts p
|
74
78
|
|
75
79
|
exit(1)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
83
|
+
# rubocop:enable Metrics/AbcSize
|
84
|
+
# rubocop:enable Metrics/MethodLength
|
85
|
+
# rubocop:enable Metrics/BlockLength
|
79
86
|
|
87
|
+
# rubocop:disable Metrics/AbcSize
|
80
88
|
def boot
|
81
|
-
ENV[
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
else
|
92
|
-
require config.require
|
93
|
-
end
|
89
|
+
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = config.env
|
90
|
+
|
91
|
+
require config.require and return unless File.directory?(config.require)
|
92
|
+
|
93
|
+
require 'rails'
|
94
|
+
raise 'Beez does not supports this version of Rails' if ::Rails::VERSION::MAJOR < 4
|
95
|
+
|
96
|
+
require File.expand_path("#{config.require}/config/environment.rb")
|
97
|
+
logger.info "Booted Rails #{::Rails.version} application in #{config.env} environment"
|
94
98
|
end
|
99
|
+
# rubocop:enable Metrics/AbcSize
|
95
100
|
|
101
|
+
# rubocop:disable Metrics/AbcSize
|
96
102
|
def launch(self_read)
|
97
103
|
@launcher = ::Beez::Launcher.new
|
98
104
|
|
99
|
-
if config.env ==
|
100
|
-
logger.info "Starting processing, hit Ctrl-C to stop"
|
101
|
-
end
|
105
|
+
logger.info 'Starting processing, hit Ctrl-C to stop' if config.env == 'development' && $stdout.tty?
|
102
106
|
|
103
107
|
begin
|
104
108
|
launcher.start
|
105
109
|
|
106
|
-
while readable_io = IO.select([self_read])
|
110
|
+
while (readable_io = IO.select([self_read]))
|
107
111
|
signal = readable_io.first[0].gets.strip
|
108
112
|
handle_signal(signal)
|
109
113
|
end
|
110
114
|
rescue Interrupt
|
111
|
-
logger.info
|
115
|
+
logger.info 'Shutting down'
|
112
116
|
launcher.stop
|
113
|
-
logger.info
|
117
|
+
logger.info 'Bye!'
|
114
118
|
|
115
119
|
exit(0)
|
116
120
|
end
|
117
121
|
end
|
122
|
+
# rubocop:enable Metrics/AbcSize
|
118
123
|
|
119
124
|
def handle_signal(signal)
|
120
125
|
handler = signal_handlers[signal]
|
@@ -127,8 +132,8 @@ module Beez
|
|
127
132
|
|
128
133
|
def signal_handlers
|
129
134
|
{
|
130
|
-
|
131
|
-
|
135
|
+
'INT' => ->(_cli) { raise Interrupt },
|
136
|
+
'TERM' => ->(_cli) { raise Interrupt }
|
132
137
|
}
|
133
138
|
end
|
134
139
|
|