eventboss 1.2.0 → 1.2.1
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/Gemfile.lock +8 -8
- data/README.md +17 -0
- data/bin/eventboss +8 -50
- data/lib/eventboss/cli.rb +148 -0
- data/lib/eventboss/configuration.rb +13 -1
- data/lib/eventboss/queue_listener.rb +22 -1
- data/lib/eventboss/runner.rb +6 -1
- data/lib/eventboss/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a0e305688c13f775cd4878f76541b9fa30a72d197ea0ea53c607dcc66b02db
|
4
|
+
data.tar.gz: 3078f03088605a062e5f703cfd36e3f76ca6028a6ca9c931eed951df5d05e8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8a13d8d088551d1ed5065551cca08a8e1904df5c3ccdd129df96429c6bae94232e4d8077bd85f6555fdbfec2689642e129c3810de3f9088a8aaf3433faf9908
|
7
|
+
data.tar.gz: d4f4812f0b535a68846004020271a5a543e1e2d66b26235419382923e8898db4cf2b1ea8490b011a8245b66c0d2320c456ea51ffce0362e628b71e1805fd2797
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eventboss (1.2.
|
4
|
+
eventboss (1.2.1)
|
5
5
|
aws-sdk-sns (>= 1.1.0)
|
6
6
|
aws-sdk-sqs (>= 1.3.0)
|
7
7
|
dotenv (~> 2.1, >= 2.1.1)
|
@@ -10,17 +10,17 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
aws-eventstream (1.0.3)
|
13
|
-
aws-partitions (1.
|
14
|
-
aws-sdk-core (3.
|
13
|
+
aws-partitions (1.228.0)
|
14
|
+
aws-sdk-core (3.72.0)
|
15
15
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
16
|
-
aws-partitions (~> 1.0)
|
16
|
+
aws-partitions (~> 1, >= 1.228.0)
|
17
17
|
aws-sigv4 (~> 1.1)
|
18
18
|
jmespath (~> 1.0)
|
19
|
-
aws-sdk-sns (1.
|
20
|
-
aws-sdk-core (~> 3, >= 3.
|
19
|
+
aws-sdk-sns (1.20.0)
|
20
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
21
21
|
aws-sigv4 (~> 1.1)
|
22
|
-
aws-sdk-sqs (1.
|
23
|
-
aws-sdk-core (~> 3, >= 3.
|
22
|
+
aws-sdk-sqs (1.23.0)
|
23
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
24
24
|
aws-sigv4 (~> 1.1)
|
25
25
|
aws-sigv4 (1.1.0)
|
26
26
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
data/README.md
CHANGED
@@ -118,6 +118,23 @@ end
|
|
118
118
|
task 'eventboss:deadletter:reload': :environment
|
119
119
|
```
|
120
120
|
|
121
|
+
Using eventboss.yml:
|
122
|
+
```yaml
|
123
|
+
concurrency: 10
|
124
|
+
listeners:
|
125
|
+
# It doesn't make much sense to use both include and exclude.
|
126
|
+
include:
|
127
|
+
- MyListener # It will run only listed listeners (MyListener). If MyListener was listed in exclude it would be omitted as well.
|
128
|
+
exclude:
|
129
|
+
- OtherListener # When include option is not set it will run all listeners except listed here (OtherListener). When include is set it will run only included (but not excluded) listeners.
|
130
|
+
```
|
131
|
+
Yml config is optional and by default is loaded from `'./config/eventboss.yml'`.
|
132
|
+
You can also pass config path as an argument:
|
133
|
+
```bash
|
134
|
+
eventboss -C my/custom/path/to/config.yml
|
135
|
+
```
|
136
|
+
Yml config content is merged to configuration last, which means it overwrites ENVs and `.configure`.
|
137
|
+
|
121
138
|
### Logging and error handling
|
122
139
|
To have more verbose logging, set `log_level` in configuration (default is `info`).
|
123
140
|
|
data/bin/eventboss
CHANGED
@@ -1,55 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'dotenv'
|
5
|
-
require 'eventboss'
|
6
|
-
require 'optparse'
|
7
|
-
|
8
|
-
Dotenv.load
|
9
|
-
|
10
|
-
STDOUT.sync = true
|
11
|
-
options = {}
|
12
|
-
|
13
|
-
OptionParser.new do |parser|
|
14
|
-
parser.on('-r', '--require LIBRARY', 'Require custom app entrypoint') do |lib|
|
15
|
-
options[:require] = lib
|
16
|
-
end
|
17
|
-
end.parse!
|
3
|
+
require 'eventboss/cli'
|
18
4
|
|
19
5
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
logger = Eventboss.logger
|
29
|
-
logger.debug('Loaded rails...')
|
30
|
-
# Due to a changes introduced in Rails 6 regarding autoloading
|
31
|
-
# we need to determine how to perform eager_load
|
32
|
-
# @see https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/
|
33
|
-
if ::Rails.try(:autoloaders).try(:zeitwerk_enabled?)
|
34
|
-
::Zeitwerk::Loader.eager_load_all
|
35
|
-
else
|
36
|
-
::Rails.application.eager_load!
|
37
|
-
end
|
38
|
-
rescue LoadError
|
39
|
-
logger = Eventboss.logger
|
40
|
-
logger.debug('Seems like not a Rails app')
|
41
|
-
|
42
|
-
if options[:require].nil?
|
43
|
-
logger.warn('Please use -r to load a custom app entrypoint')
|
44
|
-
exit(0)
|
45
|
-
else
|
46
|
-
logger.debug("Loading #{options[:require]}")
|
47
|
-
require File.expand_path(options[:require])
|
48
|
-
end
|
6
|
+
cli = Eventboss::CLI.instance
|
7
|
+
cli.parse
|
8
|
+
cli.run
|
9
|
+
rescue => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts e.backtrace.join("\n")
|
12
|
+
exit 1
|
49
13
|
end
|
50
|
-
|
51
|
-
logger.info('Starting eventboss...')
|
52
|
-
logger.info('Active Listeners:')
|
53
|
-
logger.info(Eventboss::QueueListener.list.to_s)
|
54
|
-
|
55
|
-
Eventboss.launch
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'dotenv'
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
require 'erb'
|
6
|
+
require 'singleton'
|
7
|
+
require_relative '../eventboss'
|
8
|
+
|
9
|
+
module Eventboss
|
10
|
+
class CLI
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
attr_accessor :options
|
14
|
+
|
15
|
+
DEFAULT_OPTIONS = {
|
16
|
+
require: '.'
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
self.options = DEFAULT_OPTIONS.dup
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(args = ARGV)
|
24
|
+
parse_options(args)
|
25
|
+
load_config_file
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
boot_system
|
30
|
+
|
31
|
+
Eventboss.logger.info('Starting eventboss...')
|
32
|
+
|
33
|
+
Eventboss.launch
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def boot_system
|
39
|
+
Dotenv.load
|
40
|
+
|
41
|
+
require 'rails'
|
42
|
+
if ::Rails::VERSION::MAJOR < 4
|
43
|
+
require File.expand_path('config/environment.rb')
|
44
|
+
else
|
45
|
+
require File.expand_path('config/application.rb')
|
46
|
+
require File.expand_path('config/environment.rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
Eventboss.logger.debug('Loaded rails...')
|
50
|
+
# Due to a changes introduced in Rails 6 regarding autoloading
|
51
|
+
# we need to determine how to perform eager_load
|
52
|
+
# @see https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/
|
53
|
+
if ::Rails.try(:autoloaders).try(:zeitwerk_enabled?)
|
54
|
+
::Zeitwerk::Loader.eager_load_all
|
55
|
+
else
|
56
|
+
::Rails.application.eager_load!
|
57
|
+
end
|
58
|
+
rescue LoadError
|
59
|
+
Eventboss.logger.debug('Seems like not a Rails app')
|
60
|
+
|
61
|
+
if options[:require].nil?
|
62
|
+
Eventboss.logger.warn('Please use -r to load a custom app entrypoint')
|
63
|
+
exit(0)
|
64
|
+
else
|
65
|
+
Eventboss.logger.debug("Loading #{options[:require]}")
|
66
|
+
require File.expand_path(options[:require])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_options(args)
|
71
|
+
option_parser(options).parse!(args)
|
72
|
+
|
73
|
+
options
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_config_file
|
77
|
+
# check config file presence
|
78
|
+
if options[:config]
|
79
|
+
raise ArgumentError, "No such file #{options[:config]}" unless File.exist?(options[:config])
|
80
|
+
else
|
81
|
+
config_dir = if File.directory?(options[:require].to_s)
|
82
|
+
File.join(options[:require], 'config')
|
83
|
+
else
|
84
|
+
File.join(DEFAULT_OPTIONS[:require], 'config')
|
85
|
+
end
|
86
|
+
|
87
|
+
%w[eventboss.yml eventboss.yml.erb].each do |config_file|
|
88
|
+
path = File.join(config_dir, config_file)
|
89
|
+
options[:config] ||= path if File.exist?(path)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# parse config file options
|
94
|
+
if options[:config]
|
95
|
+
opts = parse_config(options[:config])
|
96
|
+
|
97
|
+
opts.each do |option_name, option|
|
98
|
+
if Eventboss::Configuration::OPTS_ALLOWED_IN_CONFIG_FILE.include?(option_name)
|
99
|
+
Eventboss.configuration.public_send("#{option_name}=", option)
|
100
|
+
else
|
101
|
+
Eventboss.logger.error("Not supported option (#{option_name}) provided in config file.")
|
102
|
+
exit(1)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_config(path)
|
109
|
+
opts = YAML.load(ERB.new(File.read(path)).result) || {}
|
110
|
+
|
111
|
+
if opts.respond_to? :deep_symbolize_keys!
|
112
|
+
opts.deep_symbolize_keys!
|
113
|
+
else
|
114
|
+
symbolize_keys_deep!(opts)
|
115
|
+
end
|
116
|
+
|
117
|
+
opts
|
118
|
+
end
|
119
|
+
|
120
|
+
def symbolize_keys_deep!(hash)
|
121
|
+
hash.keys.each do |k|
|
122
|
+
symkey = k.respond_to?(:to_sym) ? k.to_sym : k
|
123
|
+
hash[symkey] = hash.delete k
|
124
|
+
symbolize_keys_deep! hash[symkey] if hash[symkey].is_a? Hash
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def option_parser(opts)
|
129
|
+
parser = OptionParser.new do |parser|
|
130
|
+
parser.on('-r', '--require LIBRARY', 'Require custom app entrypoint') do |lib|
|
131
|
+
opts[:require] = lib
|
132
|
+
end
|
133
|
+
|
134
|
+
parser.on('-C', '--config PATH', 'Config file path') do |config|
|
135
|
+
opts[:config] = config
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
parser.banner = "Eventboss [options]"
|
140
|
+
parser.on_tail "-h", "--help", "Show help" do
|
141
|
+
Eventboss.logger.info parser
|
142
|
+
exit 1
|
143
|
+
end
|
144
|
+
|
145
|
+
parser
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module Eventboss
|
2
2
|
class Configuration
|
3
|
+
OPTS_ALLOWED_IN_CONFIG_FILE = %i[
|
4
|
+
concurrency
|
5
|
+
sns_sqs_name_infix
|
6
|
+
listeners
|
7
|
+
]
|
8
|
+
|
3
9
|
attr_writer :raise_on_missing_configuration,
|
4
10
|
:error_handlers,
|
5
11
|
:concurrency,
|
@@ -14,7 +20,9 @@ module Eventboss
|
|
14
20
|
:aws_secret_access_key,
|
15
21
|
:aws_sns_endpoint,
|
16
22
|
:aws_sqs_endpoint,
|
17
|
-
:sns_sqs_name_infix
|
23
|
+
:sns_sqs_name_infix,
|
24
|
+
:listeners
|
25
|
+
|
18
26
|
|
19
27
|
def raise_on_missing_configuration
|
20
28
|
defined_or_default('raise_on_missing_configuration') { ENV['EVENTBUS_RAISE_ON_MISSING_CONFIGURATION']&.downcase == 'true' }
|
@@ -95,6 +103,10 @@ module Eventboss
|
|
95
103
|
defined_or_default('sns_sqs_name_infix') { ENV['EVENTBUS_SQS_SNS_NAME_INFIX'] || 'eventboss' }
|
96
104
|
end
|
97
105
|
|
106
|
+
def listeners
|
107
|
+
defined_or_default('listeners') { {} }
|
108
|
+
end
|
109
|
+
|
98
110
|
private
|
99
111
|
|
100
112
|
def defined_or_default(variable_name)
|
@@ -1,9 +1,30 @@
|
|
1
1
|
module Eventboss
|
2
2
|
class QueueListener
|
3
3
|
class << self
|
4
|
+
def select(include:, exclude:)
|
5
|
+
listeners = list.values.map(&:name)
|
6
|
+
|
7
|
+
listeners &= include if include
|
8
|
+
listeners -= exclude if exclude
|
9
|
+
|
10
|
+
list.select { |_queue, listener| listeners.include?(listener.name) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
4
15
|
def list
|
5
16
|
Hash[Eventboss::Listener::ACTIVE_LISTENERS.map do |src_app_event, listener|
|
6
|
-
[
|
17
|
+
[
|
18
|
+
Eventboss::Queue.new(
|
19
|
+
[
|
20
|
+
Eventboss.configuration.eventboss_app_name,
|
21
|
+
Eventboss.configuration.sns_sqs_name_infix,
|
22
|
+
src_app_event,
|
23
|
+
Eventboss.env
|
24
|
+
].join('-')
|
25
|
+
),
|
26
|
+
listener
|
27
|
+
]
|
7
28
|
end]
|
8
29
|
end
|
9
30
|
end
|
data/lib/eventboss/runner.rb
CHANGED
@@ -4,7 +4,10 @@ module Eventboss
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def launch
|
7
|
-
queues = Eventboss::QueueListener.
|
7
|
+
queues = Eventboss::QueueListener.select(
|
8
|
+
include: Eventboss.configuration.listeners[:include],
|
9
|
+
exclude: Eventboss.configuration.listeners[:exclude]
|
10
|
+
)
|
8
11
|
client = Eventboss.configuration.sqs_client
|
9
12
|
config = Eventboss.configuration
|
10
13
|
|
@@ -14,6 +17,8 @@ module Eventboss
|
|
14
17
|
|
15
18
|
self_read = setup_signals([:SIGTERM])
|
16
19
|
|
20
|
+
logger.info('Active Listeners:')
|
21
|
+
logger.info(queues.to_s)
|
17
22
|
begin
|
18
23
|
launcher.start
|
19
24
|
handle_signals(self_read, launcher)
|
data/lib/eventboss/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventboss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AirHelp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-sqs
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- bin/eventboss
|
122
122
|
- eventboss.gemspec
|
123
123
|
- lib/eventboss.rb
|
124
|
+
- lib/eventboss/cli.rb
|
124
125
|
- lib/eventboss/configuration.rb
|
125
126
|
- lib/eventboss/error_handlers/airbrake.rb
|
126
127
|
- lib/eventboss/error_handlers/db_connection_drop_handler.rb
|