cosmonats 0.1.0 → 0.1.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/bin/cosmo +2 -0
- data/lib/cosmo/cli.rb +43 -14
- data/lib/cosmo/engine.rb +7 -3
- data/lib/cosmo/job/processor.rb +1 -1
- data/lib/cosmo/processor.rb +2 -1
- data/lib/cosmo/stream/processor.rb +19 -13
- data/lib/cosmo/version.rb +1 -1
- data/sig/cosmo/cli.rbs +5 -1
- data/sig/cosmo/engine.rbs +1 -1
- data/sig/cosmo/processor.rbs +2 -1
- data/sig/cosmo/stream/processor.rbs +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c0995753e33b278f5a0d2d6455faf07f5c3c604595fa93c6a40260c68b69c160
|
|
4
|
+
data.tar.gz: c78c109d014f863079c3ee53171a852241b5a0b3082f9a29b1438b5708782436
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7947f18a6ab2830fa726d9903eb8ee926bf4bbf897ee71e28c262adc4aa664828c1ad758776aa61caac2964e52c83370cd4d4090c3ce05f399988c79917676e6
|
|
7
|
+
data.tar.gz: 12a7f6f7e3a715bdda711fa29acbba7db822d17cd4441b008942d7cac0eb66581f2412a4df16811580792af0913c0ffbe1370b0465478e577a6a3a45b714364b
|
data/bin/cosmo
CHANGED
data/lib/cosmo/cli.rb
CHANGED
|
@@ -14,11 +14,12 @@ module Cosmo
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def run
|
|
17
|
-
flags, command,
|
|
17
|
+
flags, command, options = parse
|
|
18
18
|
load_config(flags[:config_file])
|
|
19
19
|
puts self.class.banner
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
boot_application
|
|
21
|
+
require_path(flags[:require])
|
|
22
|
+
Engine.run(command, options)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
private
|
|
@@ -48,15 +49,23 @@ module Cosmo
|
|
|
48
49
|
Config.load(path)
|
|
49
50
|
end
|
|
50
51
|
|
|
51
|
-
def
|
|
52
|
-
|
|
52
|
+
def boot_application
|
|
53
|
+
boot_path = File.expand_path("config/boot.rb")
|
|
54
|
+
require boot_path if File.exist?(boot_path)
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
environment_path = File.expand_path("config/environment.rb")
|
|
57
|
+
require environment_path if File.exist?(environment_path)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def require_path(path)
|
|
61
|
+
if path
|
|
62
|
+
require_files(path)
|
|
63
|
+
return # If a path is provided don't load default dirs.
|
|
59
64
|
end
|
|
65
|
+
|
|
66
|
+
# Load files from app/streams if they exist.
|
|
67
|
+
# Streams are always eagerly loaded since they register classes to process events.
|
|
68
|
+
require_files("app/streams") if File.directory?("app/streams")
|
|
60
69
|
end
|
|
61
70
|
|
|
62
71
|
def flags_parser(flags) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
@@ -128,20 +137,28 @@ module Cosmo
|
|
|
128
137
|
when "streams"
|
|
129
138
|
OptionParser.new do |o|
|
|
130
139
|
o.banner = "Usage: cosmo streams [options]"
|
|
140
|
+
o.separator ""
|
|
141
|
+
o.separator " [m] many processors can be specified, in that case single options [1] are ignored"
|
|
142
|
+
o.separator " [1] options work only for a single processor"
|
|
143
|
+
o.separator ""
|
|
144
|
+
|
|
145
|
+
o.on "--processors NAMES", "[m] Specify processors names with comma" do |arg|
|
|
146
|
+
options[:processors] = arg.split(",")
|
|
147
|
+
end
|
|
131
148
|
|
|
132
|
-
o.on "--stream NAME", "Specify stream name" do |arg|
|
|
149
|
+
o.on "--stream NAME", "[1] Specify stream name" do |arg|
|
|
133
150
|
options[:stream] = arg
|
|
134
151
|
end
|
|
135
152
|
|
|
136
|
-
o.on "--subject NAME", "Specify subject name" do |arg|
|
|
153
|
+
o.on "--subject NAME", "[1] Specify subject name" do |arg|
|
|
137
154
|
options[:subject] = arg
|
|
138
155
|
end
|
|
139
156
|
|
|
140
|
-
o.on "--consumer_name NAME", "Specify consumer name" do |arg|
|
|
157
|
+
o.on "--consumer_name NAME", "[1] Specify consumer name" do |arg|
|
|
141
158
|
options[:consumer_name] = arg
|
|
142
159
|
end
|
|
143
160
|
|
|
144
|
-
o.on "--batch_size NUM", Integer, "Number of messages in the batch" do |arg|
|
|
161
|
+
o.on "--batch_size NUM", Integer, "[1] Number of messages in the batch" do |arg|
|
|
145
162
|
options[:batch_size] = arg
|
|
146
163
|
end
|
|
147
164
|
end
|
|
@@ -156,6 +173,18 @@ module Cosmo
|
|
|
156
173
|
end
|
|
157
174
|
end
|
|
158
175
|
|
|
176
|
+
def require_files(path)
|
|
177
|
+
path = File.expand_path(path)
|
|
178
|
+
|
|
179
|
+
if File.directory?(path)
|
|
180
|
+
files = Dir["#{path}/**/*.rb"]
|
|
181
|
+
files.each { |f| require f }
|
|
182
|
+
return
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
require path
|
|
186
|
+
end
|
|
187
|
+
|
|
159
188
|
# rubocop:disable Layout/TrailingWhitespace,Lint/IneffectiveAccessModifier
|
|
160
189
|
def self.banner
|
|
161
190
|
<<-TEXT
|
data/lib/cosmo/engine.rb
CHANGED
|
@@ -23,12 +23,16 @@ module Cosmo
|
|
|
23
23
|
@running = Concurrent::AtomicBoolean.new
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def run(type)
|
|
26
|
+
def run(type, options)
|
|
27
27
|
handler = Utils::Signal.trap(:INT, :TERM)
|
|
28
28
|
Logger.info "Starting processing, hit Ctrl-C to stop"
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
@processors =
|
|
30
|
+
processor_classes = type && PROCESSORS.key?(type.to_sym) ? [PROCESSORS[type.to_sym]] : PROCESSORS.values
|
|
31
|
+
@processors = processor_classes.map { _1.run(@pool, @running, options) }
|
|
32
|
+
if @running.false?
|
|
33
|
+
Logger.warn "Shutting down... (No processors are running)"
|
|
34
|
+
return
|
|
35
|
+
end
|
|
32
36
|
|
|
33
37
|
signal = handler.wait
|
|
34
38
|
Logger.info "Shutting down... (#{signal} received)"
|
data/lib/cosmo/job/processor.rb
CHANGED
data/lib/cosmo/processor.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Cosmo
|
|
4
4
|
module Stream
|
|
5
5
|
class Processor < ::Cosmo::Processor
|
|
6
|
-
def initialize(pool, running)
|
|
6
|
+
def initialize(pool, running, options)
|
|
7
7
|
super
|
|
8
8
|
@configs = {}
|
|
9
9
|
@processors = {}
|
|
@@ -63,18 +63,10 @@ module Cosmo
|
|
|
63
63
|
raise
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
def setup_configs
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
[config[:stream].to_sym, klass ? config.merge(class: klass) : nil]
|
|
71
|
-
end.compact
|
|
72
|
-
)
|
|
73
|
-
@configs.merge!(
|
|
74
|
-
Config.system[:streams].to_h do |klass|
|
|
75
|
-
[klass.default_options[:stream].to_sym, klass.default_options.merge(class: klass)]
|
|
76
|
-
end
|
|
77
|
-
)
|
|
66
|
+
def setup_configs
|
|
67
|
+
configs = static_config.merge(dynamic_config)
|
|
68
|
+
configs = configs.select { |_, c| @options[:processors].include?(c[:class].name) } if @options[:processors]
|
|
69
|
+
@configs.merge!(configs)
|
|
78
70
|
end
|
|
79
71
|
|
|
80
72
|
def setup_processors
|
|
@@ -89,6 +81,20 @@ module Cosmo
|
|
|
89
81
|
@consumers[stream_name] = client.subscribe(subjects, consumer_name, config.merge(deliver_policy))
|
|
90
82
|
end
|
|
91
83
|
end
|
|
84
|
+
|
|
85
|
+
def static_config
|
|
86
|
+
Config.dig(:consumers, :streams)&.filter_map do |config|
|
|
87
|
+
next unless (klass = Utils::String.safe_constantize(config[:class]))
|
|
88
|
+
|
|
89
|
+
[config[:stream].to_sym, config.merge(class: klass)]
|
|
90
|
+
end.to_h
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def dynamic_config
|
|
94
|
+
Config.system[:streams].to_h do |klass|
|
|
95
|
+
[klass.default_options[:stream].to_sym, klass.default_options.merge(class: klass)]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
92
98
|
end
|
|
93
99
|
end
|
|
94
100
|
end
|
data/lib/cosmo/version.rb
CHANGED
data/sig/cosmo/cli.rbs
CHANGED
|
@@ -16,7 +16,11 @@ module Cosmo
|
|
|
16
16
|
|
|
17
17
|
def load_config: (::String? path) -> void
|
|
18
18
|
|
|
19
|
-
def
|
|
19
|
+
def boot_application: () -> void
|
|
20
|
+
|
|
21
|
+
def require_path: (::String? path) -> void
|
|
22
|
+
|
|
23
|
+
def require_files: (::String path) -> void
|
|
20
24
|
|
|
21
25
|
def flags_parser: (Hash[Symbol, untyped] flags) -> untyped
|
|
22
26
|
|
data/sig/cosmo/engine.rbs
CHANGED
data/sig/cosmo/processor.rbs
CHANGED
|
@@ -3,10 +3,11 @@ module Cosmo
|
|
|
3
3
|
@pool: Utils::ThreadPool
|
|
4
4
|
@running: untyped
|
|
5
5
|
@consumers: Hash[Symbol, untyped]
|
|
6
|
+
@options: Hash[Symbol, untyped]
|
|
6
7
|
|
|
7
8
|
def self.run: (*untyped) -> Processor
|
|
8
9
|
|
|
9
|
-
def initialize: (Utils::ThreadPool pool, untyped running) -> void
|
|
10
|
+
def initialize: (Utils::ThreadPool pool, untyped running, Hash[Symbol, untyped] options) -> void
|
|
10
11
|
|
|
11
12
|
def run: () -> void
|
|
12
13
|
|