cosmonats 0.9.0 → 0.10.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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +54 -13
  3. data/lib/cosmo/active_job/adapter.rb +2 -0
  4. data/lib/cosmo/active_job/executor.rb +7 -0
  5. data/lib/cosmo/active_job/options.rb +6 -0
  6. data/lib/cosmo/api/batch.rb +26 -0
  7. data/lib/cosmo/api/counter.rb +51 -3
  8. data/lib/cosmo/api/cron/entry.rb +24 -9
  9. data/lib/cosmo/api/cron.rb +21 -7
  10. data/lib/cosmo/api/job.rb +14 -0
  11. data/lib/cosmo/api/kv.rb +138 -9
  12. data/lib/cosmo/api/registry.rb +47 -6
  13. data/lib/cosmo/api/stats/jobs.rb +84 -0
  14. data/lib/cosmo/api/stats/metrics.rb +18 -7
  15. data/lib/cosmo/api/stats/processes.rb +27 -11
  16. data/lib/cosmo/api/stats/totals.rb +1 -0
  17. data/lib/cosmo/api/stats.rb +47 -11
  18. data/lib/cosmo/api/stream.rb +66 -22
  19. data/lib/cosmo/batch/callback.rb +5 -0
  20. data/lib/cosmo/batch/dispatcher.rb +4 -4
  21. data/lib/cosmo/batch.rb +34 -11
  22. data/lib/cosmo/cli.rb +6 -0
  23. data/lib/cosmo/client.rb +208 -11
  24. data/lib/cosmo/config/cosmo.yml +1 -0
  25. data/lib/cosmo/config/settings.rb +4 -0
  26. data/lib/cosmo/config.rb +58 -10
  27. data/lib/cosmo/engine.rb +28 -1
  28. data/lib/cosmo/heartbeat.rb +12 -3
  29. data/lib/cosmo/http_server/handler.rb +5 -0
  30. data/lib/cosmo/http_server/health.rb +2 -0
  31. data/lib/cosmo/http_server/ping.rb +2 -0
  32. data/lib/cosmo/http_server.rb +8 -0
  33. data/lib/cosmo/job/data.rb +11 -0
  34. data/lib/cosmo/job/enqueuer.rb +100 -1
  35. data/lib/cosmo/job/limit.rb +5 -1
  36. data/lib/cosmo/job/processor.rb +51 -15
  37. data/lib/cosmo/job/setter.rb +53 -0
  38. data/lib/cosmo/job.rb +71 -2
  39. data/lib/cosmo/logger.rb +37 -0
  40. data/lib/cosmo/middleware/chain.rb +12 -0
  41. data/lib/cosmo/middleware/limit.rb +12 -3
  42. data/lib/cosmo/middleware/metrics.rb +6 -4
  43. data/lib/cosmo/middleware/sentry.rb +6 -4
  44. data/lib/cosmo/middleware/totals.rb +5 -11
  45. data/lib/cosmo/middleware.rb +0 -1
  46. data/lib/cosmo/processor.rb +60 -3
  47. data/lib/cosmo/publisher.rb +8 -0
  48. data/lib/cosmo/services.rb +7 -2
  49. data/lib/cosmo/stream/message.rb +5 -0
  50. data/lib/cosmo/stream/processor.rb +7 -0
  51. data/lib/cosmo/stream/serializer.rb +4 -0
  52. data/lib/cosmo/stream.rb +35 -1
  53. data/lib/cosmo/utils/duration.rb +3 -0
  54. data/lib/cosmo/utils/hash.rb +12 -0
  55. data/lib/cosmo/utils/json.rb +8 -0
  56. data/lib/cosmo/utils/signal.rb +9 -0
  57. data/lib/cosmo/utils/stopwatch.rb +1 -0
  58. data/lib/cosmo/utils/string.rb +4 -0
  59. data/lib/cosmo/utils/thread_pool.rb +8 -0
  60. data/lib/cosmo/utils/ttl_cache.rb +10 -0
  61. data/lib/cosmo/version.rb +1 -1
  62. data/lib/cosmo/web/assets/app.css +5 -3
  63. data/lib/cosmo/web/cache.rb +2 -0
  64. data/lib/cosmo/web/chart.rb +2 -2
  65. data/lib/cosmo/web/circuit.rb +1 -0
  66. data/lib/cosmo/web/context.rb +6 -0
  67. data/lib/cosmo/web/controllers/application.rb +26 -0
  68. data/lib/cosmo/web/controllers/batches.rb +7 -1
  69. data/lib/cosmo/web/controllers/crons.rb +16 -2
  70. data/lib/cosmo/web/controllers/jobs.rb +45 -16
  71. data/lib/cosmo/web/controllers/metrics.rb +5 -0
  72. data/lib/cosmo/web/controllers/overview.rb +36 -18
  73. data/lib/cosmo/web/controllers/processes.rb +8 -5
  74. data/lib/cosmo/web/controllers/streams.rb +12 -0
  75. data/lib/cosmo/web/helpers/application.rb +44 -0
  76. data/lib/cosmo/web/renderer.rb +17 -0
  77. data/lib/cosmo/web/throughput.rb +1 -1
  78. data/lib/cosmo/web/views/crons/_table.erb +29 -27
  79. data/lib/cosmo/web/views/jobs/_args.erb +2 -2
  80. data/lib/cosmo/web/views/jobs/_busy.erb +4 -4
  81. data/lib/cosmo/web/views/jobs/_enqueued.erb +2 -2
  82. data/lib/cosmo/web/views/jobs/_panel.erb +6 -1
  83. data/lib/cosmo/web/views/layout.erb +1 -1
  84. data/lib/cosmo/web/views/overview/_badges.erb +1 -1
  85. data/lib/cosmo/web/views/overview/_running.erb +3 -3
  86. data/lib/cosmo/web/views/overview/index.erb +1 -1
  87. data/lib/cosmo/web/views/streams/_info.erb +1 -0
  88. data/lib/cosmo/web/views/streams/_stream.erb +1 -0
  89. data/lib/cosmo/web.rb +8 -1
  90. data/lib/cosmo.rb +33 -0
  91. data/sig/cosmo/active_job/adapter.rbs +3 -3
  92. data/sig/cosmo/active_job/options.rbs +4 -2
  93. data/sig/cosmo/api/batch.rbs +5 -3
  94. data/sig/cosmo/api/counter.rbs +16 -6
  95. data/sig/cosmo/api/cron/entry.rbs +4 -2
  96. data/sig/cosmo/api/cron.rbs +10 -4
  97. data/sig/cosmo/api/kv.rbs +21 -4
  98. data/sig/cosmo/api/registry.rbs +10 -0
  99. data/sig/cosmo/api/stats/jobs.rbs +34 -0
  100. data/sig/cosmo/api/stats/metrics.rbs +3 -0
  101. data/sig/cosmo/api/stats/processes.rbs +9 -1
  102. data/sig/cosmo/api/stats.rbs +8 -2
  103. data/sig/cosmo/api/stream.rbs +10 -5
  104. data/sig/cosmo/batch/callback.rbs +1 -1
  105. data/sig/cosmo/batch/dispatcher.rbs +1 -1
  106. data/sig/cosmo/batch.rbs +5 -5
  107. data/sig/cosmo/cli.rbs +2 -0
  108. data/sig/cosmo/client.rbs +23 -4
  109. data/sig/cosmo/config/settings.rbs +6 -0
  110. data/sig/cosmo/config.rbs +5 -5
  111. data/sig/cosmo/engine.rbs +5 -0
  112. data/sig/cosmo/heartbeat.rbs +2 -0
  113. data/sig/cosmo/job/data.rbs +3 -1
  114. data/sig/cosmo/job/enqueuer.rbs +12 -0
  115. data/sig/cosmo/job/processor.rbs +18 -3
  116. data/sig/cosmo/job/setter.rbs +20 -0
  117. data/sig/cosmo/job.rbs +10 -4
  118. data/sig/cosmo/logger.rbs +5 -3
  119. data/sig/cosmo/middleware.rbs +0 -8
  120. data/sig/cosmo/processor.rbs +14 -2
  121. data/sig/cosmo/publisher.rbs +1 -0
  122. data/sig/cosmo/stream/processor.rbs +4 -0
  123. data/sig/cosmo/stream.rbs +4 -3
  124. data/sig/cosmo/utils/hash.rbs +2 -1
  125. data/sig/cosmo/utils/signal.rbs +5 -5
  126. data/sig/cosmo/utils/string.rbs +2 -2
  127. data/sig/cosmo/utils/thread_pool.rbs +1 -1
  128. data/sig/cosmo/web/cache.rbs +35 -0
  129. data/sig/cosmo/web/chart.rbs +48 -0
  130. data/sig/cosmo/web/circuit.rbs +29 -0
  131. data/sig/cosmo/web/context.rbs +15 -0
  132. data/sig/cosmo/web/controllers/application.rbs +32 -0
  133. data/sig/cosmo/web/controllers/batches.rbs +11 -0
  134. data/sig/cosmo/web/controllers/crons.rbs +23 -0
  135. data/sig/cosmo/web/controllers/jobs.rbs +47 -0
  136. data/sig/cosmo/web/controllers/metrics.rbs +21 -0
  137. data/sig/cosmo/web/controllers/overview.rbs +31 -0
  138. data/sig/cosmo/web/controllers/processes.rbs +13 -0
  139. data/sig/cosmo/web/controllers/streams.rbs +27 -0
  140. data/sig/cosmo/web/helpers/application.rbs +61 -0
  141. data/sig/cosmo/web/renderer.rbs +33 -0
  142. data/sig/cosmo/web/throughput.rbs +45 -0
  143. data/sig/cosmo/web.rbs +25 -0
  144. data/sig/cosmo.rbs +19 -0
  145. metadata +23 -6
  146. data/lib/cosmo/api/stats/busy.rb +0 -68
  147. data/lib/cosmo/middleware/busy.rb +0 -15
  148. data/sig/cosmo/api/stats/busy.rbs +0 -33
@@ -11,9 +11,11 @@ module Cosmo
11
11
  attr_reader timezone: ::String?
12
12
  attr_reader name: ::String?
13
13
 
14
- def self.normalize_expression: (untyped expr) -> ::String
14
+ @job_name: ::String
15
15
 
16
- def initialize: (class_name: ::String, stream: ::String, expression: ::String,
16
+ def self.normalize_expression: (::String? expr) -> ::String
17
+
18
+ def initialize: (class_name: ::String?, stream: ::String?, expression: ::String?,
17
19
  ?args: ::Array[untyped], ?timezone: ::String?, ?name: (::String | ::Symbol)?) -> void
18
20
 
19
21
  def schedule_subject: () -> ::String
@@ -3,15 +3,19 @@ module Cosmo
3
3
  class Cron
4
4
  STREAM: ::String
5
5
 
6
+ self.@instance: Cron
7
+ @client: Client
8
+
9
+ def self.instance: () -> Cron
10
+
6
11
  def all: () -> ::Array[Hash[Symbol, untyped]]
7
12
 
8
- def upsert!: (?Cosmo::API::Cron::Entry schedule_obj,
9
- ?class_name: ::String?,
13
+ def upsert!: (?class_name: ::String?,
10
14
  ?stream: ::String?,
11
- ?expression: ::String?,
15
+ ?schedule: ::String?,
12
16
  ?args: ::Array[untyped],
13
17
  ?timezone: ::String?,
14
- ?name: ::String?) -> Hash[Symbol, untyped]?
18
+ ?name: (::String | ::Symbol)?) -> Hash[Symbol, untyped]?
15
19
 
16
20
  def delete!: (::String subject) -> void
17
21
 
@@ -19,8 +23,10 @@ module Cosmo
19
23
 
20
24
  private
21
25
 
26
+ def client: () -> Client
22
27
  def schedules: () -> ::Array[Hash[Symbol, untyped]]
23
28
  def build_from_nats: (::String subject) -> Hash[Symbol, untyped]?
29
+ def build: (::String subject, Hash[::String, ::String]? headers, ::String data) -> Hash[Symbol, untyped]?
24
30
  def name_from_subject: (::String subject) -> ::String?
25
31
  end
26
32
  end
data/sig/cosmo/api/kv.rbs CHANGED
@@ -6,26 +6,41 @@ module Cosmo
6
6
  @name: ::String
7
7
  @options: Hash[Symbol, untyped]
8
8
  @kv: untyped
9
+ @direct: true
9
10
 
10
11
  attr_reader kv: untyped
11
12
 
12
13
  def initialize: (::String name, ?Hash[Symbol, untyped]? options) -> void
13
14
 
14
- def set: (::String | ::Integer key, untyped value, ?ttl: ::Integer?) -> untyped
15
+ def set: (::String | ::Integer key, untyped value, ?ttl: ::Integer?) -> ::Integer
15
16
 
16
17
  def get: (::String | ::Integer key) -> untyped
17
18
 
18
- def delete: (::String | ::Integer key) -> untyped
19
+ def create: (::String | ::Integer key, untyped value) -> ::Integer
20
+
21
+ def delete: (::String | ::Integer key) -> ::Integer
19
22
 
20
23
  def keys: (?::String? subject, ?limit: ::Integer?, ?offset: ::Integer) -> Array[::String]
21
24
 
22
25
  def entries: (?::String? subject, ?limit: ::Integer?, ?offset: ::Integer) -> Array[[::String, ::String]]
23
26
 
27
+ def direct_entries: (?::String? subject, ?limit: ::Integer?) -> Array[[::String, ::String]]
28
+
29
+ def direct_count: (?::String? subject) -> ::Integer
30
+
31
+ def direct_keys: (?::String? subject) -> Array[::String]
32
+
33
+ def direct_values: (Array[::String] keys) -> Hash[::String, ::String]
34
+
35
+ def write_many: (Hash[::String, untyped] pairs, ?ttl: ::Integer?) -> void
36
+
37
+ def direct!: () -> true
38
+
24
39
  def purge: (::String | ::Integer key) -> untyped
25
40
 
26
41
  def erase: (::String | ::Integer key) -> ::Integer?
27
42
 
28
- def clean: () -> untyped
43
+ def clean: () -> ::Integer?
29
44
 
30
45
  def count: () -> ::Integer
31
46
  alias size count
@@ -34,7 +49,9 @@ module Cosmo
34
49
 
35
50
  def walk: (::String? subject, limit: ::Integer?, offset: ::Integer, meta_only: bool) -> Array[[::String, ::String]]
36
51
 
37
- def publish_cas: (::String | ::Integer key, ::String value, ::Integer? ttl, last_seq: ::Integer) -> untyped
52
+ def drained?: (untyped watcher, ::Integer seen) -> bool
53
+
54
+ def publish_cas: (::String | ::Integer key, ::String value, ::Integer ttl, last_seq: ::Integer) -> untyped
38
55
 
39
56
  def client: () -> Client
40
57
  end
@@ -2,16 +2,24 @@ module Cosmo
2
2
  module API
3
3
  class Registry
4
4
  LIMIT: ::Integer
5
+ KEYS_TTL: ::Integer
5
6
 
6
7
  self.@instance: Registry
7
8
  @kv: KV
9
+ @keys_mutex: Mutex
10
+ @keys: Array[::String]
11
+ @keys_at: Float
8
12
 
9
13
  def self.instance: () -> instance
10
14
 
15
+ def self.token: (untyped value) -> ::String
16
+
11
17
  def initialize: () -> void
12
18
 
13
19
  def put: (::String | ::Integer key, Hash[Symbol, untyped] value) -> void
14
20
 
21
+ def put_many: (Hash[::String, Hash[Symbol, untyped]] entries, ?ttl: ::Integer?) -> void
22
+
15
23
  def remove: (::String | ::Integer key) -> void
16
24
 
17
25
  def list: (?page: ::Integer?, ?limit: ::Integer) -> Array[Hash[Symbol, untyped]]
@@ -22,6 +30,8 @@ module Cosmo
22
30
 
23
31
  private
24
32
 
33
+ def keys: () -> Array[::String]
34
+
25
35
  def bucket: () -> KV
26
36
 
27
37
  def sanitize: (::String | ::Integer key) -> ::String
@@ -0,0 +1,34 @@
1
+ module Cosmo
2
+ module API
3
+ module Stats
4
+ class Jobs < Registry
5
+ TTL: ::Integer
6
+ BUCKET: ::String
7
+ LONGEST_TTL: ::Integer
8
+ ENTRY_TTL: ::Integer
9
+
10
+ @mutex: Mutex
11
+ @longest: Array[Hash[Symbol, untyped]]
12
+ @longest_at: Float
13
+
14
+ def initialize: () -> void
15
+
16
+ def report: (::String identity, Array[Hash[Symbol, untyped]] jobs) -> void
17
+
18
+ def clear: (::String identity) -> void
19
+
20
+ def count: (?::String? stream) -> ::Integer
21
+
22
+ def sample: (::Integer limit) -> Array[Hash[Symbol, untyped]]
23
+
24
+ def longest: (?page: ::Integer?, ?limit: ::Integer) -> Array[Hash[Symbol, untyped]]
25
+
26
+ private
27
+
28
+ def bucket: () -> KV
29
+
30
+ def key_for: (::String identity, Hash[Symbol, untyped] job) -> ::String
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,6 +5,7 @@ module Cosmo
5
5
  STREAM_NAME: ::String
6
6
  DESCRIPTION: ::String
7
7
  DAY: Integer
8
+ CLOCK_SKEW: Integer
8
9
 
9
10
  self.@instance: Metrics
10
11
 
@@ -31,6 +32,8 @@ module Cosmo
31
32
 
32
33
  def read: (Integer days) -> Array[[[::String, ::String, Symbol], Integer]]
33
34
 
35
+ def since: (::String day) -> ::Time
36
+
34
37
  def dates: (Integer days) -> Array[::String]
35
38
 
36
39
  def row: (Hash[Symbol, Numeric] sums) -> Hash[Symbol, untyped]
@@ -6,13 +6,21 @@ module Cosmo
6
6
  BUCKET: ::String
7
7
  KINDS: Array[::String]
8
8
 
9
+ @registered: Hash[::String, ::String]
10
+
9
11
  def self.kind: (Hash[Symbol, untyped] process) -> ::String
10
12
 
11
- def list: (?page: ::Integer?, ?limit: ::Integer) -> Array[Hash[Symbol, untyped]]
13
+ def initialize: () -> void
14
+
15
+ def threads: () -> ::Integer
12
16
 
13
17
  def register: (::String identity, Hash[Symbol, untyped] info) -> void
14
18
 
15
19
  def unregister: (::String identity) -> void
20
+
21
+ private
22
+
23
+ def key_for: (::String identity, Hash[Symbol, untyped] info) -> ::String
16
24
  end
17
25
  end
18
26
  end
@@ -7,11 +7,17 @@ module Cosmo
7
7
 
8
8
  def self.failed: () -> ::Integer
9
9
 
10
+ def self.running: (::Integer limit) -> Array[Hash[Symbol, untyped]]
11
+
12
+ def self.running_page: (page: ::Integer, limit: ::Integer, ?longest: bool) -> Array[Hash[Symbol, untyped]]
13
+
10
14
  def self.busy: () -> ::Integer
11
15
 
12
- def self.enqueued: () -> ::Integer
16
+ def self.busy_streams: (?Array[Stream] streams) -> Hash[::String, ::Integer]
17
+
18
+ def self.enqueued: (?Array[Stream] streams) -> ::Integer
13
19
 
14
- def self.retries: () -> ::Integer
20
+ def self.retries: (?Array[Stream] streams) -> ::Integer
15
21
 
16
22
  def self.scheduled: () -> ::Integer
17
23
 
@@ -5,7 +5,8 @@ module Cosmo
5
5
 
6
6
  self.@client: Client
7
7
  @name: ::String
8
- @offset: ::Integer
8
+ @info: untyped
9
+ @offset: ::Integer?
9
10
 
10
11
  def self.all: () -> Array[Stream]
11
12
 
@@ -15,11 +16,11 @@ module Cosmo
15
16
 
16
17
  attr_reader name: ::String
17
18
 
18
- def initialize: (::String name) -> void
19
+ def initialize: (::String name, ?untyped info) -> void
19
20
 
20
21
  def info: () -> Hash[Symbol, untyped]
21
22
 
22
- def offset: (::Integer) -> self
23
+ def offset: (::Integer value) -> self
23
24
 
24
25
  def total: () -> ::Integer
25
26
  alias size total
@@ -30,13 +31,13 @@ module Cosmo
30
31
 
31
32
  def each: () { (Job) -> void } -> void
32
33
 
33
- def messages: (?page: ::Integer?, ?limit: ::Integer?) -> Array[Job]
34
+ def messages: (?page: ::Integer?, ?limit: ::Integer?, ?order: :asc | :desc) -> Array[Job]
34
35
 
35
36
  def message: (::Integer seq) -> Job?
36
37
 
37
38
  def retry: (::Integer seq) -> void
38
39
 
39
- def delete: (::Integer seq) -> untyped
40
+ def delete: (::Integer seq) -> Hash[::String, untyped]
40
41
 
41
42
  def pause!: () -> untyped
42
43
 
@@ -46,6 +47,10 @@ module Cosmo
46
47
 
47
48
  private
48
49
 
50
+ def messages_asc: (::Integer page, ::Integer limit) -> Array[Job]
51
+
52
+ def messages_desc: (::Integer page, ::Integer limit) -> Array[Job]
53
+
49
54
  def scan_range: () -> [::Integer, ::Integer, Array[::String]]
50
55
 
51
56
  def next_candidate: (Array[::String] subjects, Hash[::String, Job?] candidates, ::Integer current) -> [::String, Job]?
@@ -3,7 +3,7 @@ module Cosmo
3
3
  class Callback
4
4
  include Cosmo::Job
5
5
 
6
- def perform: (::String class_name, Symbol event, Hash[Symbol, untyped] status, Hash[Symbol, untyped] opts) -> void
6
+ def perform: (::String class_name, ::String | Symbol event, Hash[Symbol, untyped] status, Hash[Symbol, untyped] opts) -> void
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Cosmo
3
3
  module Dispatcher
4
4
  private
5
5
 
6
- def release_pending: (::String bid, ?msg_id: ::String?) -> void
6
+ def release_pending: (::String bid, ?by: Integer, ?msg_id: ::String?) -> void
7
7
 
8
8
  def finalize: (::String bid) -> void
9
9
 
data/sig/cosmo/batch.rbs CHANGED
@@ -23,15 +23,15 @@ module Cosmo
23
23
 
24
24
  attr_reader parent_id: ::String?
25
25
 
26
- def initialize: (?parent: ::String?) -> void
26
+ def initialize: (?bid: ::String?, ?parent: ::String?) -> void
27
27
 
28
- def jobs: () { () -> void } -> void
28
+ def jobs: [T] () { () -> T } -> T
29
29
 
30
30
  def on: (Symbol event, Class klass, **untyped) -> void
31
31
 
32
- def register_job!: () -> void
32
+ def register_job!: (?Integer count) -> void
33
33
 
34
- def rollback_job!: () -> void
34
+ def rollback_job!: (?Integer count) -> void
35
35
 
36
36
  private
37
37
 
@@ -41,7 +41,7 @@ module Cosmo
41
41
 
42
42
  def link: (::String parent_id) -> void
43
43
 
44
- def release_pending: () -> void
44
+ def release_pending: (?Integer count) -> void
45
45
 
46
46
  def try_fire: (Symbol event) -> void
47
47
  end
data/sig/cosmo/cli.rbs CHANGED
@@ -22,6 +22,8 @@ module Cosmo
22
22
 
23
23
  def run_init: () -> void
24
24
 
25
+ def run_setup: (Hash[Symbol, untyped] flags) -> void
26
+
25
27
  def boot_application: () -> void
26
28
 
27
29
  def require_path: (::String? path) -> void
data/sig/cosmo/client.rbs CHANGED
@@ -3,6 +3,7 @@ module Cosmo
3
3
  JS_TIMEOUT: ::Integer
4
4
  CONNECT_TIMEOUT: ::Integer
5
5
  MAX_RECONNECT_ATTEMPTS: ::Integer
6
+ DIRECT_BATCH: ::Integer
6
7
 
7
8
  attr_reader name: ::String
8
9
 
@@ -25,6 +26,8 @@ module Cosmo
25
26
 
26
27
  def publish: (::String subject, ::String payload, **untyped params) -> untyped
27
28
 
29
+ def publish_many: (Array[{ subject: ::String, payload: ::String, header: Hash[::String, untyped] }] messages) -> Array[untyped]
30
+
28
31
  def subscribe: (::String | Array[::String] subject, ::String? consumer_name, Hash[Symbol, untyped] config) -> untyped
29
32
 
30
33
  def stream_info: (::String | Symbol name) -> untyped
@@ -39,7 +42,7 @@ module Cosmo
39
42
 
40
43
  def cron_subjects_in_stream: (::String stream_name, ::String filter) -> Array[::String]
41
44
 
42
- def list_streams: () -> Array[Hash[::String, untyped]]
45
+ def list_streams: () -> Array[untyped]
43
46
 
44
47
  def pause_stream: (::String name) -> void
45
48
 
@@ -49,13 +52,19 @@ module Cosmo
49
52
 
50
53
  def list_consumers: (::String stream_name) -> Array[Hash[::String, untyped]]
51
54
 
52
- def consumer_info: (::String stream_name, ::String consumer_name) -> NATS::JetStream::API::ConsumerInfo
55
+ def consumer_info: (::String stream_name, ::String consumer_name) -> untyped
53
56
 
54
57
  def delete_consumer: (::String stream_name, ::String consumer_name) -> bool
55
58
 
56
- def get_message: (::String | Symbol name, **untyped options) -> NATS::JetStream::API::RawStreamMsg
59
+ def get_message: (::String | Symbol name, **untyped options) -> untyped
60
+
61
+ def last_messages: (::String stream_name, Array[::String] filters) -> Hash[::String, NATS::Msg]
62
+
63
+ def direct_messages: (::String stream_name, ::String filter, ?limit: ::Integer?, ?since: ::Time?) -> Array[NATS::Msg]
57
64
 
58
- def last_messages: (::String stream_name, Array[::String] filters) -> Hash[::String, ::String]
65
+ def count_messages: (::String stream_name, ::String filter) -> ::Integer
66
+
67
+ def subjects: (::String stream_name, ::String filter) -> Array[::String]
59
68
 
60
69
  def delete_message: (::String name, ::Integer seq) -> Hash[::String, untyped]
61
70
 
@@ -67,6 +76,16 @@ module Cosmo
67
76
 
68
77
  private
69
78
 
79
+ def direct_batch: (::String stream_name, Hash[Symbol, untyped] request, Array[NATS::Msg] messages) -> [::Integer?, ::Integer]
80
+
81
+ def direct_pending: (::String stream_name, Hash[::String, ::String] header) -> ::Integer
82
+
83
+ def acks: (untyped subscription, Integer count) -> Array[untyped]
84
+
85
+ def next_reply: (untyped subscription, Float deadline) -> untyped
86
+
87
+ def pub_ack: (untyped reply) -> untyped
88
+
70
89
  def ephemeral_subscribe: (::String | Array[::String] subject, Hash[Symbol, untyped] config) -> untyped
71
90
 
72
91
  def create_kv_with_msg_ttl: (::String name, ?replicas: Integer, **untyped opts) -> untyped
@@ -1,5 +1,11 @@
1
1
  module Cosmo
2
2
  class Config < ::Hash[Symbol, untyped]
3
+ class Services
4
+ attr_accessor num_replicas: Integer
5
+
6
+ def self.new: (num_replicas: Integer) -> Services
7
+ end
8
+
3
9
  class Scheduled
4
10
  attr_accessor enabled: bool
5
11
 
data/sig/cosmo/config.rbs CHANGED
@@ -16,6 +16,8 @@ module Cosmo
16
16
 
17
17
  def self.read: (::String path) -> Hash[Symbol, untyped]
18
18
 
19
+ def self.flatten_groups!: (Hash[Symbol, untyped] config) -> void
20
+
19
21
  def self.parse_file: (::String path) -> Hash[Symbol, untyped]
20
22
 
21
23
  def self.build: (Hash[Symbol, untyped] user) -> Hash[Symbol, untyped]
@@ -34,7 +36,7 @@ module Cosmo
34
36
 
35
37
  def self.load: (?::String? path, ?overrides: Hash[Symbol, untyped]?) -> void
36
38
 
37
- def self.replicas: () -> Integer
39
+ def self.services: () -> Services
38
40
 
39
41
  def self.scheduled: () -> Scheduled
40
42
 
@@ -64,14 +66,12 @@ module Cosmo
64
66
 
65
67
  def error_handlers: () -> Array[untyped]
66
68
 
67
- @replicas: Integer?
69
+ @services: Services
68
70
  @scheduled: Scheduled
69
71
  @dead: Dead
70
72
  @batches: Batches
71
73
 
72
- attr_writer replicas: Integer
73
-
74
- def replicas: () -> Integer
74
+ def services: () -> Services
75
75
 
76
76
  def scheduled: () -> Scheduled
77
77
 
data/sig/cosmo/engine.rbs CHANGED
@@ -1,6 +1,7 @@
1
1
  module Cosmo
2
2
  class Engine
3
3
  PROCESSORS: Hash[Symbol, Class]
4
+ INTERRUPT_TIMEOUT: Integer
4
5
 
5
6
  self.@instance: Engine
6
7
  @concurrency: Integer
@@ -29,6 +30,8 @@ module Cosmo
29
30
 
30
31
  def busy: () -> Integer
31
32
 
33
+ def jobs: () -> Array[Hash[Symbol, untyped]]
34
+
32
35
  def subscriptions: () -> Hash[Symbol, Array[::String]]
33
36
 
34
37
  def shutdown: () -> void
@@ -45,6 +48,8 @@ module Cosmo
45
48
 
46
49
  def drain_and_exit: (Utils::Signal handler) -> void
47
50
 
51
+ def terminate: () -> void
52
+
48
53
  def dump_threads: () -> void
49
54
  end
50
55
  end
@@ -34,5 +34,7 @@ module Cosmo
34
34
  def rss: () -> ::Integer?
35
35
 
36
36
  def processes: () -> API::Stats::Processes
37
+
38
+ def jobs: () -> API::Stats::Jobs
37
39
  end
38
40
  end
@@ -15,13 +15,15 @@ module Cosmo
15
15
 
16
16
  def initialize: (::String class_name, Array[untyped] args, ?Hash[Symbol, untyped]? options) -> void
17
17
 
18
+ def batch_id: () -> ::String?
19
+
18
20
  def stream: (?target: bool) -> Symbol
19
21
 
20
22
  def subject: () -> ::String
21
23
 
22
24
  def headers: () -> Hash[::String, untyped]
23
25
 
24
- def as_json: () -> { jid: ::String, class: ::String, args: Array[untyped], retry: Integer, dead: bool }
26
+ def as_json: () -> { jid: ::String, class: ::String, args: Array[untyped], retry: Integer, dead: bool, ?batch_id: ::String }
25
27
 
26
28
  def to_json: (*untyped _args) -> ::String?
27
29
 
@@ -1,8 +1,20 @@
1
1
  module Cosmo
2
2
  module Job
3
3
  module Enqueuer
4
+ CHUNK_SIZE: Integer
5
+
4
6
  def self.enqueue: (::String class_name, Array[untyped] args, Hash[Symbol, untyped] options, ?batch: Batch?) -> ::String?
5
7
 
8
+ def self.enqueue_many: (::String class_name, Array[Array[untyped]] list, Hash[Symbol, untyped] options, ?batch: Batch?) -> Array[::String?]
9
+
10
+ def self.publish_chunk: (::String class_name, Array[Array[untyped]] chunk, Hash[Symbol, untyped] options, Batch? batch) -> [Array[::String?], Hash[Integer, StandardError]]
11
+
12
+ def self.through_middleware: (::String class_name, Data data) -> [Data, Hash[Symbol, untyped]]?
13
+
14
+ def self.publish_all: (Array[[Data, Hash[Symbol, untyped]]] jobs, Batch? batch) -> Array[untyped]
15
+
16
+ def self.collect: (Array[[Data, Hash[Symbol, untyped]]?] jobs, Array[untyped] results) -> [Array[::String?], Hash[Integer, StandardError]]
17
+
6
18
  def self.pipe: (::String class_name, Data data) -> bool
7
19
 
8
20
  def self.publish: (Data data, Hash[Symbol, untyped] payload) -> untyped
@@ -2,6 +2,7 @@ module Cosmo
2
2
  module Job
3
3
  class Processor < ::Cosmo::Processor
4
4
  DISPATCH_HEADERS: ::Array[::String]
5
+ ARGS_LIMIT: ::Integer
5
6
 
6
7
  @weights: Array[Symbol]?
7
8
 
@@ -9,8 +10,14 @@ module Cosmo
9
10
 
10
11
  def subscriptions: () -> Array[::String]
11
12
 
13
+ def jobs: () -> Array[Hash[Symbol, untyped]]
14
+
12
15
  private
13
16
 
17
+ def job_entry: (untyped message, ::Integer? started_at) -> Hash[Symbol, untyped]
18
+
19
+ def capped_args: (untyped args) -> untyped
20
+
14
21
  def setup: () -> void
15
22
 
16
23
  def log_subscriptions: () -> void
@@ -20,7 +27,9 @@ module Cosmo
20
27
  def consumer_name: (::String | Symbol stream_name) -> ::String
21
28
 
22
29
  def schedule_loop: () -> void
30
+
23
31
  def scheduled_by: (untyped message) -> ::String?
32
+
24
33
  def enqueued_at: (untyped message) -> ::Time
25
34
 
26
35
  def scheduler?: () -> bool
@@ -33,6 +42,12 @@ module Cosmo
33
42
 
34
43
  def process: (Array[untyped] messages, untyped processor) -> void
35
44
 
45
+ def build_worker: (untyped worker_class, Hash[Symbol, untyped] data, untyped message) -> Cosmo::Job
46
+
47
+ def abandon: (untyped message) -> bool
48
+
49
+ def notify_batch: (Hash[Symbol, untyped] data, success: bool) -> void
50
+
36
51
  def handle_failure: (untyped worker_class, untyped message, Hash[Symbol, untyped] data, Exception? exception) -> bool
37
52
 
38
53
  def nak_message: (untyped worker_class, untyped message, Hash[Symbol, untyped] data, Integer current_attempt, Exception? exception) -> void
@@ -49,15 +64,15 @@ module Cosmo
49
64
 
50
65
  def subscribe: (Symbol stream_name, Hash[Symbol, untyped] config) -> [untyped, Hash[Symbol, untyped], nil]
51
66
 
52
- def drop_message: (untyped message, Hash[Symbol, untyped] data) -> void
67
+ def drop_message: (untyped message, Hash[Symbol, untyped]? data) -> void
53
68
 
54
- def reject_message: (untyped message, Exception error, ?Hash[Symbol, untyped]? data) -> void
69
+ def reject_message: (untyped message, Exception error) -> void
55
70
 
56
71
  def error_context: (untyped message, Hash[Symbol, untyped]? data, ?source: Symbol) -> Hash[Symbol, untyped]
57
72
 
58
73
  def move_message: (untyped message, ?Hash[Symbol, untyped]? data, ?Exception? exception) -> void
59
74
 
60
- def perform_job: (untyped job_instance, data: Hash[Symbol, untyped], message: untyped) -> untyped
75
+ def perform_job: (Cosmo::Job? job_instance, data: Hash[Symbol, untyped], message: untyped) -> untyped
61
76
  end
62
77
  end
63
78
  end
@@ -0,0 +1,20 @@
1
+ module Cosmo
2
+ module Job
3
+ class Setter
4
+ OPTIONS: Array[Symbol]
5
+
6
+ @job_class: ClassMethods
7
+ @options: Hash[Symbol, untyped]
8
+
9
+ def initialize: (ClassMethods job_class, Hash[Symbol, untyped] options) -> void
10
+
11
+ def perform_async: (*untyped args) -> ::String?
12
+
13
+ def perform_bulk: (Array[Array[untyped]] list) -> Array[::String?]
14
+
15
+ def perform_at: (Integer | Time timestamp, *untyped args) -> ::String?
16
+
17
+ def perform_in: (Numeric interval, *untyped args) -> ::String?
18
+ end
19
+ end
20
+ end
data/sig/cosmo/job.rbs CHANGED
@@ -8,7 +8,7 @@ module Cosmo
8
8
  def options: (**untyped config) -> Hash[Symbol, untyped]
9
9
  alias cosmo_options options
10
10
 
11
- def concurrency_options: () -> { limit: Integer, key: Proc?, duration: Integer }?
11
+ def concurrency_options: () -> { limit: Integer, key: Proc?, duration: Integer, retry_in: Integer }?
12
12
 
13
13
  def concurrency_key: (Array[untyped] args) -> ::String?
14
14
 
@@ -18,11 +18,15 @@ module Cosmo
18
18
 
19
19
  def perform: (*untyped args, ?async: bool, **untyped options) -> (::String | nil)
20
20
 
21
- def perform_async: (*untyped args) -> ::String
21
+ def set: (**untyped options) -> Setter
22
22
 
23
- def perform_at: (Integer | Time timestamp, *untyped args) -> ::String
23
+ def perform_async: (*untyped args) -> ::String?
24
24
 
25
- def perform_in: (Integer | Float interval, *untyped args) -> ::String
25
+ def perform_bulk: (Array[Array[untyped]] list, **untyped options) -> Array[::String?]
26
+
27
+ def perform_at: (Integer | Time timestamp, *untyped args) -> ::String?
28
+
29
+ def perform_in: (Numeric interval, *untyped args) -> ::String?
26
30
 
27
31
  def perform_sync: (*untyped args) -> void
28
32
 
@@ -35,6 +39,8 @@ module Cosmo
35
39
 
36
40
  attr_accessor jid: ::String
37
41
 
42
+ attr_accessor batch_id: ::String?
43
+
38
44
  attr_accessor enqueued_at: ::Time?
39
45
 
40
46
  attr_accessor attempt: ::Integer?