cosmonats 0.3.0 → 0.4.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +208 -156
  3. data/lib/cosmo/active_job/adapter.rb +46 -0
  4. data/lib/cosmo/active_job/executor.rb +16 -0
  5. data/lib/cosmo/active_job/options.rb +50 -0
  6. data/lib/cosmo/active_job.rb +29 -0
  7. data/lib/cosmo/api/busy.rb +2 -2
  8. data/lib/cosmo/api/counter.rb +2 -2
  9. data/lib/cosmo/api/cron/entry.rb +99 -0
  10. data/lib/cosmo/api/cron.rb +118 -0
  11. data/lib/cosmo/api/kv.rb +35 -13
  12. data/lib/cosmo/api/stream.rb +10 -5
  13. data/lib/cosmo/api.rb +1 -0
  14. data/lib/cosmo/cli.rb +27 -10
  15. data/lib/cosmo/client.rb +48 -2
  16. data/lib/cosmo/config.rb +9 -0
  17. data/lib/cosmo/job/data.rb +1 -1
  18. data/lib/cosmo/job/limit.rb +51 -0
  19. data/lib/cosmo/job/processor.rb +49 -5
  20. data/lib/cosmo/job.rb +51 -2
  21. data/lib/cosmo/processor.rb +1 -1
  22. data/lib/cosmo/railtie.rb +21 -0
  23. data/lib/cosmo/stream/processor.rb +2 -2
  24. data/lib/cosmo/stream.rb +2 -1
  25. data/lib/cosmo/utils/hash.rb +13 -0
  26. data/lib/cosmo/utils/overrides.rb +1 -1
  27. data/lib/cosmo/version.rb +1 -1
  28. data/lib/cosmo/web/assets/app.css +42 -0
  29. data/lib/cosmo/web/controllers/crons.rb +41 -0
  30. data/lib/cosmo/web/controllers/jobs.rb +7 -3
  31. data/lib/cosmo/web/controllers/streams.rb +1 -1
  32. data/lib/cosmo/web/helpers/application.rb +4 -0
  33. data/lib/cosmo/web/views/actions/index.erb +1 -1
  34. data/lib/cosmo/web/views/crons/_table.erb +58 -0
  35. data/lib/cosmo/web/views/crons/index.erb +10 -0
  36. data/lib/cosmo/web/views/jobs/_busy.erb +54 -49
  37. data/lib/cosmo/web/views/jobs/_dead.erb +70 -65
  38. data/lib/cosmo/web/views/jobs/_enqueued.erb +82 -56
  39. data/lib/cosmo/web/views/jobs/_scheduled.erb +53 -48
  40. data/lib/cosmo/web/views/jobs/_tabs.erb +6 -0
  41. data/lib/cosmo/web/views/jobs/busy.erb +8 -6
  42. data/lib/cosmo/web/views/jobs/dead.erb +6 -5
  43. data/lib/cosmo/web/views/jobs/enqueued.erb +8 -6
  44. data/lib/cosmo/web/views/jobs/index.erb +1 -1
  45. data/lib/cosmo/web/views/jobs/scheduled.erb +6 -5
  46. data/lib/cosmo/web/views/layout.erb +1 -1
  47. data/lib/cosmo/web.rb +5 -0
  48. data/lib/cosmo.rb +1 -0
  49. data/sig/cosmo/active_job/adapter.rbs +13 -0
  50. data/sig/cosmo/active_job/executor.rbs +9 -0
  51. data/sig/cosmo/active_job/options.rbs +14 -0
  52. data/sig/cosmo/api/cron/entry.rbs +30 -0
  53. data/sig/cosmo/api/cron.rbs +25 -0
  54. data/sig/cosmo/api/kv.rbs +4 -6
  55. data/sig/cosmo/client.rbs +9 -1
  56. data/sig/cosmo/job/data.rbs +1 -1
  57. data/sig/cosmo/job/limit.rbs +18 -0
  58. data/sig/cosmo/job/processor.rbs +3 -1
  59. data/sig/cosmo/job.rbs +9 -4
  60. data/sig/cosmo/railtie.rbs +4 -0
  61. data/sig/cosmo/utils/hash.rbs +4 -0
  62. metadata +20 -1
data/sig/cosmo/api/kv.rbs CHANGED
@@ -5,11 +5,13 @@ module Cosmo
5
5
  @options: Hash[Symbol, untyped]
6
6
  @kv: untyped
7
7
 
8
+ attr_reader kv: untyped
9
+
8
10
  def initialize: (::String name, ?Hash[Symbol, untyped]? options) -> void
9
11
 
10
- def set: (::String | ::Integer key, ::String value) -> untyped
12
+ def set: (::String | ::Integer key, untyped value, ?ttl: ::Integer?) -> untyped
11
13
 
12
- def get: (::String | ::Integer key) -> ::String?
14
+ def get: (::String | ::Integer key) -> untyped
13
15
 
14
16
  def delete: (::String | ::Integer key) -> untyped
15
17
 
@@ -21,10 +23,6 @@ module Cosmo
21
23
 
22
24
  def count: () -> ::Integer
23
25
  alias size count
24
-
25
- private
26
-
27
- def kv: () -> untyped
28
26
  end
29
27
  end
30
28
  end
data/sig/cosmo/client.rbs CHANGED
@@ -23,6 +23,10 @@ module Cosmo
23
23
 
24
24
  def update_stream: (::String | Symbol name, Hash[Symbol, untyped] config) -> untyped
25
25
 
26
+ def setup_stream: (::String name, Hash[Symbol, untyped] config) -> untyped
27
+
28
+ def cron_subjects_in_stream: (::String stream_name, ::String filter) -> Array[::String]
29
+
26
30
  def list_streams: () -> Array[Hash[::String, untyped]]
27
31
 
28
32
  def pause_stream: (::String name) -> void
@@ -41,8 +45,12 @@ module Cosmo
41
45
 
42
46
  def purge: (::String stream_name, ::String? subject) -> ::Integer?
43
47
 
44
- def kv: (::String name, **untyped opts) -> NATS::KeyValue
48
+ def kv: (::String name, ?allow_msg_ttl: bool, **untyped opts) -> untyped
45
49
 
46
50
  def close: -> void
51
+
52
+ private
53
+
54
+ def create_kv_with_msg_ttl: (::String name, **untyped opts) -> untyped
47
55
  end
48
56
  end
@@ -1,7 +1,7 @@
1
1
  module Cosmo
2
2
  module Job
3
3
  class Data
4
- DEFAULTS: { stream: Symbol, retry: Integer | bool, dead: bool }
4
+ DEFAULTS: { stream: Symbol, retry: Integer, dead: bool, limit: nil }
5
5
 
6
6
  @class_name: ::String
7
7
  @args: Array[untyped]
@@ -0,0 +1,18 @@
1
+ module Cosmo
2
+ module Job
3
+ class Limit
4
+ BUCKET: ::String
5
+
6
+ self.@instance: Limit
7
+
8
+ def self.instance: () -> Limit
9
+
10
+ def initialize: () -> void
11
+
12
+ def acquire: (::String key, jid: ::String, limit: ::Integer, duration: ::Integer) -> ::String?
13
+
14
+ def release: (::String slot) -> void
15
+ end
16
+ end
17
+ end
18
+
@@ -17,7 +17,7 @@ module Cosmo
17
17
 
18
18
  def process: (Array[untyped] messages, untyped processor) -> void
19
19
 
20
- def handle_failure: (untyped message, Hash[Symbol, untyped] data) -> void
20
+ def handle_failure: (untyped message, Hash[Symbol, untyped] data) -> bool
21
21
 
22
22
  def subscribe: (Symbol stream_name, Hash[Symbol, untyped] config) -> [untyped, Hash[Symbol, untyped], nil]
23
23
 
@@ -26,6 +26,8 @@ module Cosmo
26
26
  def move_message: (untyped message, ?Hash[Symbol, untyped]? data) -> void
27
27
 
28
28
  def with_stats: (untyped message) { () -> untyped } -> void
29
+
30
+ def acquire_concurrency_slot: (untyped worker_class, untyped message, Hash[Symbol, untyped] data) -> (::String | false)
29
31
  end
30
32
  end
31
33
  end
data/sig/cosmo/job.rbs CHANGED
@@ -5,7 +5,14 @@ module Cosmo
5
5
  module ClassMethods
6
6
  @default_options: Hash[Symbol, untyped]
7
7
 
8
- def options: (?stream: Symbol?, ?retry: Integer?, ?dead: bool?) -> Hash[Symbol, untyped]
8
+ def options: (**untyped config) -> Hash[Symbol, untyped]
9
+ alias cosmo_options options
10
+
11
+ def concurrency_options: () -> { limit: Integer, key: Proc?, duration: Integer }?
12
+
13
+ def concurrency_key: (Array[untyped] args) -> ::String?
14
+
15
+ def limits_concurrency?: () -> bool
9
16
 
10
17
  def perform: (*untyped args, ?async: bool, **untyped options) -> (::String | nil)
11
18
 
@@ -24,9 +31,7 @@ module Cosmo
24
31
  def client: () -> Client
25
32
  end
26
33
 
27
- attr_reader jid: ::String
28
-
29
- def jid=: (::String) -> ::String
34
+ attr_accessor jid: ::String
30
35
 
31
36
  def perform: (*untyped) -> untyped
32
37
 
@@ -0,0 +1,4 @@
1
+ module Cosmo
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -3,12 +3,16 @@ module Cosmo
3
3
  module Hash
4
4
  def self.symbolize_keys!: (untyped obj) -> (::Hash[Symbol, untyped] | Array[untyped] | untyped)
5
5
 
6
+ def self.stringify_keys: (untyped obj) -> (::Hash[String, untyped] | Array[untyped] | untyped)
7
+
6
8
  def self.dup: [T] (T hash) -> T
7
9
 
8
10
  def self.set: (::Hash[untyped, untyped] hash, *untyped keys, value: untyped) -> untyped
9
11
 
10
12
  def symbolize_keys!: (untyped obj) -> (::Hash[Symbol, untyped] | Array[untyped] | untyped)
11
13
 
14
+ def stringify_keys: (untyped obj) -> (::Hash[String, untyped] | Array[untyped] | untyped)
15
+
12
16
  def dup: [T] (T hash) -> T
13
17
 
14
18
  def set: (::Hash[untyped, untyped] hash, *untyped keys, value: untyped) -> untyped
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
@@ -63,9 +63,15 @@ files:
63
63
  - README.md
64
64
  - bin/cosmo
65
65
  - lib/cosmo.rb
66
+ - lib/cosmo/active_job.rb
67
+ - lib/cosmo/active_job/adapter.rb
68
+ - lib/cosmo/active_job/executor.rb
69
+ - lib/cosmo/active_job/options.rb
66
70
  - lib/cosmo/api.rb
67
71
  - lib/cosmo/api/busy.rb
68
72
  - lib/cosmo/api/counter.rb
73
+ - lib/cosmo/api/cron.rb
74
+ - lib/cosmo/api/cron/entry.rb
69
75
  - lib/cosmo/api/job.rb
70
76
  - lib/cosmo/api/kv.rb
71
77
  - lib/cosmo/api/stats.rb
@@ -76,10 +82,12 @@ files:
76
82
  - lib/cosmo/engine.rb
77
83
  - lib/cosmo/job.rb
78
84
  - lib/cosmo/job/data.rb
85
+ - lib/cosmo/job/limit.rb
79
86
  - lib/cosmo/job/processor.rb
80
87
  - lib/cosmo/logger.rb
81
88
  - lib/cosmo/processor.rb
82
89
  - lib/cosmo/publisher.rb
90
+ - lib/cosmo/railtie.rb
83
91
  - lib/cosmo/stream.rb
84
92
  - lib/cosmo/stream/data.rb
85
93
  - lib/cosmo/stream/message.rb
@@ -102,16 +110,20 @@ files:
102
110
  - lib/cosmo/web/context.rb
103
111
  - lib/cosmo/web/controllers/actions.rb
104
112
  - lib/cosmo/web/controllers/application.rb
113
+ - lib/cosmo/web/controllers/crons.rb
105
114
  - lib/cosmo/web/controllers/jobs.rb
106
115
  - lib/cosmo/web/controllers/streams.rb
107
116
  - lib/cosmo/web/helpers/application.rb
108
117
  - lib/cosmo/web/renderer.rb
109
118
  - lib/cosmo/web/views/actions/index.erb
119
+ - lib/cosmo/web/views/crons/_table.erb
120
+ - lib/cosmo/web/views/crons/index.erb
110
121
  - lib/cosmo/web/views/jobs/_busy.erb
111
122
  - lib/cosmo/web/views/jobs/_dead.erb
112
123
  - lib/cosmo/web/views/jobs/_enqueued.erb
113
124
  - lib/cosmo/web/views/jobs/_scheduled.erb
114
125
  - lib/cosmo/web/views/jobs/_stats.erb
126
+ - lib/cosmo/web/views/jobs/_tabs.erb
115
127
  - lib/cosmo/web/views/jobs/busy.erb
116
128
  - lib/cosmo/web/views/jobs/dead.erb
117
129
  - lib/cosmo/web/views/jobs/enqueued.erb
@@ -126,8 +138,13 @@ files:
126
138
  - lib/cosmo/web/views/streams/info.erb
127
139
  - lib/cosmonats.rb
128
140
  - sig/cosmo.rbs
141
+ - sig/cosmo/active_job/adapter.rbs
142
+ - sig/cosmo/active_job/executor.rbs
143
+ - sig/cosmo/active_job/options.rbs
129
144
  - sig/cosmo/api/busy.rbs
130
145
  - sig/cosmo/api/counter.rbs
146
+ - sig/cosmo/api/cron.rbs
147
+ - sig/cosmo/api/cron/entry.rbs
131
148
  - sig/cosmo/api/job.rbs
132
149
  - sig/cosmo/api/kv.rbs
133
150
  - sig/cosmo/api/stats.rbs
@@ -138,10 +155,12 @@ files:
138
155
  - sig/cosmo/engine.rbs
139
156
  - sig/cosmo/job.rbs
140
157
  - sig/cosmo/job/data.rbs
158
+ - sig/cosmo/job/limit.rbs
141
159
  - sig/cosmo/job/processor.rbs
142
160
  - sig/cosmo/logger.rbs
143
161
  - sig/cosmo/processor.rbs
144
162
  - sig/cosmo/publisher.rbs
163
+ - sig/cosmo/railtie.rbs
145
164
  - sig/cosmo/stream.rbs
146
165
  - sig/cosmo/stream/data.rbs
147
166
  - sig/cosmo/stream/message.rbs