cosmonats 0.7.0 → 0.8.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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +199 -103
  3. data/lib/cosmo/active_job/adapter.rb +1 -2
  4. data/lib/cosmo/api/counter.rb +16 -16
  5. data/lib/cosmo/api/cron.rb +3 -0
  6. data/lib/cosmo/api/registry.rb +1 -1
  7. data/lib/cosmo/api/stats/busy.rb +1 -1
  8. data/lib/cosmo/api/stats/metrics.rb +109 -0
  9. data/lib/cosmo/api/stats/processes.rb +14 -4
  10. data/lib/cosmo/api/stats/totals.rb +4 -12
  11. data/lib/cosmo/api/stats.rb +3 -2
  12. data/lib/cosmo/batch/counters.rb +19 -0
  13. data/lib/cosmo/batch.rb +6 -6
  14. data/lib/cosmo/cli.rb +21 -5
  15. data/lib/cosmo/client.rb +28 -2
  16. data/lib/cosmo/config/cosmo.yml +58 -0
  17. data/lib/cosmo/config/settings.rb +20 -0
  18. data/lib/cosmo/config.rb +144 -19
  19. data/lib/cosmo/heartbeat.rb +11 -0
  20. data/lib/cosmo/job/data.rb +17 -12
  21. data/lib/cosmo/job/enqueuer.rb +53 -0
  22. data/lib/cosmo/job/limit.rb +2 -2
  23. data/lib/cosmo/job/processor.rb +27 -52
  24. data/lib/cosmo/job/requeue.rb +20 -0
  25. data/lib/cosmo/job.rb +8 -22
  26. data/lib/cosmo/logger.rb +15 -2
  27. data/lib/cosmo/middleware/busy.rb +15 -0
  28. data/lib/cosmo/middleware/chain.rb +137 -0
  29. data/lib/cosmo/middleware/limit.rb +50 -0
  30. data/lib/cosmo/middleware/metrics.rb +39 -0
  31. data/lib/cosmo/{sentry/job_processor_middleware.rb → middleware/sentry.rb} +26 -30
  32. data/lib/cosmo/middleware/totals.rb +29 -0
  33. data/lib/cosmo/middleware.rb +7 -0
  34. data/lib/cosmo/processor.rb +11 -5
  35. data/lib/cosmo/publisher.rb +1 -13
  36. data/lib/cosmo/railtie.rb +2 -2
  37. data/lib/cosmo/services.rb +69 -0
  38. data/lib/cosmo/stream/processor.rb +7 -1
  39. data/lib/cosmo/utils/hash.rb +7 -8
  40. data/lib/cosmo/version.rb +1 -1
  41. data/lib/cosmo/web/assets/app.css +58 -0
  42. data/lib/cosmo/web/chart.rb +98 -0
  43. data/lib/cosmo/web/controllers/crons.rb +8 -0
  44. data/lib/cosmo/web/controllers/jobs.rb +16 -2
  45. data/lib/cosmo/web/controllers/metrics.rb +48 -0
  46. data/lib/cosmo/web/helpers/application.rb +10 -0
  47. data/lib/cosmo/web/views/batches/_table.erb +11 -0
  48. data/lib/cosmo/web/views/jobs/_processes.erb +49 -35
  49. data/lib/cosmo/web/views/jobs/_stats.erb +4 -0
  50. data/lib/cosmo/web/views/jobs/_tabs.erb +6 -0
  51. data/lib/cosmo/web/views/jobs/index.erb +1 -1
  52. data/lib/cosmo/web/views/layout.erb +1 -1
  53. data/lib/cosmo/web/views/metrics/_chart.erb +36 -0
  54. data/lib/cosmo/web/views/metrics/_panel.erb +13 -0
  55. data/lib/cosmo/web/views/metrics/_table.erb +41 -0
  56. data/lib/cosmo/web/views/metrics/index.erb +17 -0
  57. data/lib/cosmo/web.rb +3 -0
  58. data/lib/cosmo.rb +38 -0
  59. data/sig/cosmo/api/counter.rbs +2 -3
  60. data/sig/cosmo/api/stats/busy.rbs +1 -1
  61. data/sig/cosmo/api/stats/metrics.rbs +42 -0
  62. data/sig/cosmo/api/stats/processes.rbs +3 -0
  63. data/sig/cosmo/api/stats/totals.rbs +3 -2
  64. data/sig/cosmo/batch/counters.rbs +10 -0
  65. data/sig/cosmo/batch.rbs +3 -4
  66. data/sig/cosmo/cli.rbs +2 -0
  67. data/sig/cosmo/client.rbs +3 -1
  68. data/sig/cosmo/config/settings.rbs +31 -0
  69. data/sig/cosmo/config.rbs +59 -5
  70. data/sig/cosmo/heartbeat.rbs +2 -0
  71. data/sig/cosmo/job/data.rbs +5 -3
  72. data/sig/cosmo/job/enqueuer.rbs +11 -0
  73. data/sig/cosmo/job/processor.rbs +3 -5
  74. data/sig/cosmo/job/requeue.rbs +9 -0
  75. data/sig/cosmo/job.rbs +0 -2
  76. data/sig/cosmo/logger.rbs +6 -0
  77. data/sig/cosmo/middleware/chain.rbs +51 -0
  78. data/sig/cosmo/middleware/sentry.rbs +14 -0
  79. data/sig/cosmo/middleware.rbs +35 -0
  80. data/sig/cosmo/processor.rbs +2 -0
  81. data/sig/cosmo/publisher.rbs +1 -9
  82. data/sig/cosmo/services.rbs +18 -0
  83. data/sig/cosmo/stream/processor.rbs +2 -0
  84. data/sig/cosmo/utils/hash.rbs +2 -3
  85. data/sig/cosmo.rbs +11 -0
  86. metadata +30 -3
  87. data/lib/cosmo/sentry/auto.rb +0 -6
@@ -17,6 +17,8 @@ module Cosmo
17
17
 
18
18
  def beat: () -> void
19
19
 
20
+ def flush: () -> void
21
+
20
22
  def identity: () -> ::String
21
23
 
22
24
  def info: () -> Hash[Symbol, untyped]
@@ -17,16 +17,18 @@ module Cosmo
17
17
 
18
18
  def stream: (?target: bool) -> Symbol
19
19
 
20
- def subject: (?target: bool) -> Array[::String]
20
+ def subject: () -> ::String
21
+
22
+ def headers: () -> Hash[::String, untyped]
21
23
 
22
24
  def as_json: () -> { jid: ::String, class: ::String, args: Array[untyped], retry: Integer, dead: bool }
23
25
 
24
26
  def to_json: (*untyped _args) -> ::String?
25
27
 
26
- def to_args: () -> [::String, ::String, Hash[Symbol, untyped]]
27
-
28
28
  private
29
29
 
30
+ def subject_for: (Symbol | ::String stream) -> ::String
31
+
30
32
  def validate!: () -> void
31
33
 
32
34
  def retries: () -> Integer
@@ -0,0 +1,11 @@
1
+ module Cosmo
2
+ module Job
3
+ module Enqueuer
4
+ def self.enqueue: (::String class_name, Array[untyped] args, Hash[Symbol, untyped] options, ?batch: Batch?) -> ::String?
5
+
6
+ def self.pipe: (::String class_name, Data data) -> bool
7
+
8
+ def self.publish: (Data data, Hash[Symbol, untyped] payload) -> untyped
9
+ end
10
+ end
11
+ end
@@ -53,13 +53,11 @@ module Cosmo
53
53
 
54
54
  def reject_message: (untyped message, Exception error, ?Hash[Symbol, untyped]? data) -> void
55
55
 
56
- def move_message: (untyped message, ?Hash[Symbol, untyped]? data, ?Exception? exception) -> void
57
-
58
- def with_stats: (untyped message) { () -> untyped } -> void
56
+ def error_context: (untyped message, Hash[Symbol, untyped]? data, ?source: Symbol) -> Hash[Symbol, untyped]
59
57
 
60
- def acquire_concurrency_slot: (untyped worker_class, untyped message, Hash[Symbol, untyped] data) -> (::String | false)
58
+ def move_message: (untyped message, ?Hash[Symbol, untyped]? data, ?Exception? exception) -> void
61
59
 
62
- def perform_job: (untyped job_instance, data: Hash[Symbol, untyped], message: untyped, ?duration: Float?) -> untyped
60
+ def perform_job: (untyped job_instance, data: Hash[Symbol, untyped], message: untyped) -> untyped
63
61
  end
64
62
  end
65
63
  end
@@ -0,0 +1,9 @@
1
+ module Cosmo
2
+ module Job
3
+ class Requeue < StandardError
4
+ attr_reader delay: Numeric
5
+
6
+ def initialize: (?Numeric delay) -> void
7
+ end
8
+ end
9
+ end
data/sig/cosmo/job.rbs CHANGED
@@ -31,8 +31,6 @@ module Cosmo
31
31
  private
32
32
 
33
33
  def client: () -> Client
34
-
35
- def publish: (Data data, Batch? batch) -> void
36
34
  end
37
35
 
38
36
  attr_accessor jid: ::String
data/sig/cosmo/logger.rbs CHANGED
@@ -45,5 +45,11 @@ module Cosmo
45
45
  def self.without: (*Symbol) -> nil
46
46
 
47
47
  def self.instance: () -> untyped
48
+
49
+ def self.instance=: (untyped logger) -> void
50
+
51
+ def self.level=: (Symbol | ::String | Integer level) -> void
52
+
53
+ def self.coerce_level: (Symbol | ::String | Integer level) -> Integer
48
54
  end
49
55
  end
@@ -0,0 +1,51 @@
1
+ module Cosmo
2
+ module Middleware
3
+ class Chain
4
+ include Enumerable[Entry]
5
+
6
+ class Entry
7
+ attr_accessor klass: Class
8
+ attr_accessor args: Array[untyped]
9
+ attr_accessor kwargs: Hash[Symbol, untyped]
10
+
11
+ def self.new: (Class klass, Array[untyped] args, Hash[Symbol, untyped] kwargs) -> Entry
12
+
13
+ def build: () -> untyped
14
+ end
15
+
16
+ @entries: Array[Entry]
17
+
18
+ def initialize: () ?{ (Chain chain) -> void } -> void
19
+
20
+ def each: () { (Entry entry) -> void } -> Array[Entry]
21
+
22
+ def add: (Class klass, *untyped args, **untyped kwargs) -> Chain
23
+
24
+ def prepend: (Class klass, *untyped args, **untyped kwargs) -> Chain
25
+
26
+ def insert_before: (Class existing, Class klass, *untyped args, **untyped kwargs) -> Chain
27
+
28
+ def insert_after: (Class existing, Class klass, *untyped args, **untyped kwargs) -> Chain
29
+
30
+ def remove: (Class klass) -> Chain
31
+
32
+ def exists?: (Class klass) -> bool
33
+
34
+ alias include? exists?
35
+
36
+ def empty?: () -> bool
37
+
38
+ def clear: () -> Chain
39
+
40
+ def invoke: (*untyped args) { () -> untyped } -> untyped
41
+
42
+ private
43
+
44
+ def traverse: (Array[untyped] chain, Integer position, Array[untyped] args) { () -> untyped } -> untyped
45
+
46
+ def index: (Class klass) -> Integer?
47
+
48
+ def take: (Class klass, Array[untyped] args, Hash[Symbol, untyped] kwargs) -> Entry
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ module Cosmo
2
+ module Middleware
3
+ class Sentry
4
+ NAME_PREFIX: ::String
5
+ OP_NAME: ::String
6
+ SPAN_ORIGIN: ::String
7
+ STATUS_OK: ::Integer
8
+ STATUS_FAIL: ::Integer
9
+ ERROR_HANDLER: ^(Exception error, Hash[Symbol, untyped] context) -> void
10
+
11
+ def call: (untyped job, Hash[Symbol, untyped] data, untyped message) { () -> untyped } -> untyped
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module Cosmo
2
+ module Middleware
3
+ class Limit
4
+ def call: (untyped job, Hash[Symbol, untyped] data, untyped message) { () -> untyped } -> untyped
5
+
6
+ private
7
+
8
+ def acquire: (untyped job_class, Hash[Symbol, untyped] data) -> ::String?
9
+
10
+ def timeout: (Numeric? duration) { () -> untyped } -> untyped
11
+ end
12
+
13
+ class Busy
14
+ def call: (untyped job, Hash[Symbol, untyped] data, untyped message) { () -> untyped } -> untyped
15
+ end
16
+
17
+ class Metrics
18
+ def call: (untyped job, Hash[Symbol, untyped] data, untyped message) { () -> untyped } -> untyped
19
+
20
+ private
21
+
22
+ def job_name: (untyped job, Hash[Symbol, untyped] data) -> ::String
23
+
24
+ def clock: () -> Float
25
+ end
26
+
27
+ class Totals
28
+ def call: (untyped job, Hash[Symbol, untyped] data, untyped message) { () -> untyped } -> untyped
29
+
30
+ private
31
+
32
+ def increment: (Symbol key) -> void
33
+ end
34
+ end
35
+ end
@@ -60,5 +60,7 @@ module Cosmo
60
60
  def stopwatch: () -> Utils::Stopwatch
61
61
 
62
62
  def consumer_state: () -> untyped
63
+
64
+ def backoff_key: (Hash[Symbol, untyped] config) -> String
63
65
  end
64
66
  end
@@ -4,18 +4,10 @@ module Cosmo
4
4
 
5
5
  def self.instance: () -> Publisher
6
6
 
7
- def self.publish: (::String subject, untyped data, ?serializer: Module?, **untyped options) -> bool
8
-
9
- def self.publish_job: (Job::Data data) -> ::String
10
-
11
- def self.publish_batch: (::String subject, Array[untyped] batch, **untyped options) -> void
7
+ def self.publish: (::String subject, untyped data, ?serializer: Module?, **untyped options) -> untyped
12
8
 
13
9
  def initialize: () -> void
14
10
 
15
11
  def publish: (::String subject, untyped data, ?serializer: Module?, **untyped options) -> untyped
16
-
17
- def publish_job: (Job::Data data) -> ::String
18
-
19
- def publish_batch: (::String subject, Array[untyped] batch, **untyped options) -> void
20
12
  end
21
13
  end
@@ -0,0 +1,18 @@
1
+ module Cosmo
2
+ module Services
3
+ SCHEDULED: ::String
4
+ DEAD: ::String
5
+ METADATA: Hash[::String, ::String]
6
+ RETENTION_CHANGE: Integer
7
+
8
+ def self.scheduled_stream: () -> Hash[Symbol, untyped]?
9
+
10
+ def self.scheduled_consumer: () -> Hash[Symbol, untyped]?
11
+
12
+ def self.dead_stream: () -> Hash[Symbol, untyped]?
13
+
14
+ def self.setup!: () -> Array[::String]
15
+
16
+ def self.setup_stream: (::String name, Hash[Symbol, untyped] config) -> void
17
+ end
18
+ end
@@ -13,6 +13,8 @@ module Cosmo
13
13
 
14
14
  def fetch_subjects: (Hash[Symbol, untyped] config) -> untyped
15
15
 
16
+ def backoff_key: (Hash[Symbol, untyped] config) -> String
17
+
16
18
  def fetch_timeout: (Hash[Symbol, untyped] config) -> Float
17
19
 
18
20
  def static_config: -> Array[Hash[Symbol, untyped]]
@@ -7,15 +7,14 @@ module Cosmo
7
7
 
8
8
  def self.dup: [T] (T hash) -> T
9
9
 
10
- def self.set: (::Hash[untyped, untyped] hash, *untyped keys, value: untyped) -> untyped
11
-
12
10
  def symbolize_keys!: (untyped obj) -> (::Hash[Symbol, untyped] | Array[untyped] | untyped)
13
11
 
14
12
  def stringify_keys: (untyped obj) -> (::Hash[String, untyped] | Array[untyped] | untyped)
15
13
 
14
+ def deep_merge: (::Hash[untyped, untyped] base, ::Hash[untyped, untyped] other) -> ::Hash[untyped, untyped]
15
+
16
16
  def dup: [T] (T hash) -> T
17
17
 
18
- def set: (::Hash[untyped, untyped] hash, *untyped keys, value: untyped) -> untyped
19
18
  end
20
19
  end
21
20
  end
data/sig/cosmo.rbs CHANGED
@@ -1,6 +1,10 @@
1
1
  module Cosmo
2
2
  VERSION: ::String
3
3
 
4
+ def self.configure: () { (Config config) -> void } -> void
5
+
6
+ def self.handle_error: (Exception error, Hash[Symbol, untyped] context) -> void
7
+
4
8
  class Error < StandardError
5
9
  end
6
10
 
@@ -10,10 +14,17 @@ module Cosmo
10
14
  class NotImplementedError < Error
11
15
  end
12
16
 
17
+ class ConfigError < Error
18
+ end
19
+
13
20
  class ConfigNotFoundError < Error
14
21
  def initialize: (::String config_file) -> void
15
22
  end
16
23
 
24
+ class SchedulingDisabledError < Error
25
+ def initialize: () -> void
26
+ end
27
+
17
28
  class StreamNotFoundError < Error
18
29
  def initialize: (::String stream_name) -> void
19
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cosmonats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
@@ -83,15 +83,19 @@ files:
83
83
  - lib/cosmo/api/registry.rb
84
84
  - lib/cosmo/api/stats.rb
85
85
  - lib/cosmo/api/stats/busy.rb
86
+ - lib/cosmo/api/stats/metrics.rb
86
87
  - lib/cosmo/api/stats/processes.rb
87
88
  - lib/cosmo/api/stats/totals.rb
88
89
  - lib/cosmo/api/stream.rb
89
90
  - lib/cosmo/batch.rb
90
91
  - lib/cosmo/batch/callback.rb
92
+ - lib/cosmo/batch/counters.rb
91
93
  - lib/cosmo/batch/dispatcher.rb
92
94
  - lib/cosmo/cli.rb
93
95
  - lib/cosmo/client.rb
94
96
  - lib/cosmo/config.rb
97
+ - lib/cosmo/config/cosmo.yml
98
+ - lib/cosmo/config/settings.rb
95
99
  - lib/cosmo/engine.rb
96
100
  - lib/cosmo/heartbeat.rb
97
101
  - lib/cosmo/http_server.rb
@@ -100,16 +104,24 @@ files:
100
104
  - lib/cosmo/http_server/ping.rb
101
105
  - lib/cosmo/job.rb
102
106
  - lib/cosmo/job/data.rb
107
+ - lib/cosmo/job/enqueuer.rb
103
108
  - lib/cosmo/job/failure.rb
104
109
  - lib/cosmo/job/limit.rb
105
110
  - lib/cosmo/job/processor.rb
111
+ - lib/cosmo/job/requeue.rb
106
112
  - lib/cosmo/job/stream_filter.rb
107
113
  - lib/cosmo/logger.rb
114
+ - lib/cosmo/middleware.rb
115
+ - lib/cosmo/middleware/busy.rb
116
+ - lib/cosmo/middleware/chain.rb
117
+ - lib/cosmo/middleware/limit.rb
118
+ - lib/cosmo/middleware/metrics.rb
119
+ - lib/cosmo/middleware/sentry.rb
120
+ - lib/cosmo/middleware/totals.rb
108
121
  - lib/cosmo/processor.rb
109
122
  - lib/cosmo/publisher.rb
110
123
  - lib/cosmo/railtie.rb
111
- - lib/cosmo/sentry/auto.rb
112
- - lib/cosmo/sentry/job_processor_middleware.rb
124
+ - lib/cosmo/services.rb
113
125
  - lib/cosmo/stream.rb
114
126
  - lib/cosmo/stream/data.rb
115
127
  - lib/cosmo/stream/message.rb
@@ -130,12 +142,14 @@ files:
130
142
  - lib/cosmo/web.rb
131
143
  - lib/cosmo/web/assets/app.css
132
144
  - lib/cosmo/web/assets/htmx.2.0.8.min.js.gz
145
+ - lib/cosmo/web/chart.rb
133
146
  - lib/cosmo/web/context.rb
134
147
  - lib/cosmo/web/controllers/actions.rb
135
148
  - lib/cosmo/web/controllers/application.rb
136
149
  - lib/cosmo/web/controllers/batches.rb
137
150
  - lib/cosmo/web/controllers/crons.rb
138
151
  - lib/cosmo/web/controllers/jobs.rb
152
+ - lib/cosmo/web/controllers/metrics.rb
139
153
  - lib/cosmo/web/controllers/streams.rb
140
154
  - lib/cosmo/web/helpers/application.rb
141
155
  - lib/cosmo/web/renderer.rb
@@ -157,6 +171,10 @@ files:
157
171
  - lib/cosmo/web/views/jobs/index.erb
158
172
  - lib/cosmo/web/views/jobs/scheduled.erb
159
173
  - lib/cosmo/web/views/layout.erb
174
+ - lib/cosmo/web/views/metrics/_chart.erb
175
+ - lib/cosmo/web/views/metrics/_panel.erb
176
+ - lib/cosmo/web/views/metrics/_table.erb
177
+ - lib/cosmo/web/views/metrics/index.erb
160
178
  - lib/cosmo/web/views/streams/_info.erb
161
179
  - lib/cosmo/web/views/streams/_pause_banner.erb
162
180
  - lib/cosmo/web/views/streams/_stream_row.erb
@@ -177,15 +195,18 @@ files:
177
195
  - sig/cosmo/api/registry.rbs
178
196
  - sig/cosmo/api/stats.rbs
179
197
  - sig/cosmo/api/stats/busy.rbs
198
+ - sig/cosmo/api/stats/metrics.rbs
180
199
  - sig/cosmo/api/stats/processes.rbs
181
200
  - sig/cosmo/api/stats/totals.rbs
182
201
  - sig/cosmo/api/stream.rbs
183
202
  - sig/cosmo/batch.rbs
184
203
  - sig/cosmo/batch/callback.rbs
204
+ - sig/cosmo/batch/counters.rbs
185
205
  - sig/cosmo/batch/dispatcher.rbs
186
206
  - sig/cosmo/cli.rbs
187
207
  - sig/cosmo/client.rbs
188
208
  - sig/cosmo/config.rbs
209
+ - sig/cosmo/config/settings.rbs
189
210
  - sig/cosmo/engine.rbs
190
211
  - sig/cosmo/heartbeat.rbs
191
212
  - sig/cosmo/http_server.rbs
@@ -194,14 +215,20 @@ files:
194
215
  - sig/cosmo/http_server/ping.rbs
195
216
  - sig/cosmo/job.rbs
196
217
  - sig/cosmo/job/data.rbs
218
+ - sig/cosmo/job/enqueuer.rbs
197
219
  - sig/cosmo/job/failure.rbs
198
220
  - sig/cosmo/job/limit.rbs
199
221
  - sig/cosmo/job/processor.rbs
222
+ - sig/cosmo/job/requeue.rbs
200
223
  - sig/cosmo/job/stream_filter.rbs
201
224
  - sig/cosmo/logger.rbs
225
+ - sig/cosmo/middleware.rbs
226
+ - sig/cosmo/middleware/chain.rbs
227
+ - sig/cosmo/middleware/sentry.rbs
202
228
  - sig/cosmo/processor.rbs
203
229
  - sig/cosmo/publisher.rbs
204
230
  - sig/cosmo/railtie.rbs
231
+ - sig/cosmo/services.rbs
205
232
  - sig/cosmo/stream.rbs
206
233
  - sig/cosmo/stream/data.rbs
207
234
  - sig/cosmo/stream/message.rbs
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cosmo/job/processor"
4
- require "cosmo/sentry/job_processor_middleware"
5
-
6
- Cosmo::Job::Processor.prepend Cosmo::Sentry::JobProcessorMiddleware