cosmonats 0.1.4 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +129 -67
- data/lib/cosmo/api/busy.rb +66 -0
- data/lib/cosmo/api/counter.rb +70 -0
- data/lib/cosmo/api/job.rb +46 -0
- data/lib/cosmo/api/kv.rb +63 -0
- data/lib/cosmo/api/stats.rb +44 -0
- data/lib/cosmo/api/stream.rb +123 -0
- data/lib/cosmo/api.rb +11 -0
- data/lib/cosmo/cli.rb +8 -5
- data/lib/cosmo/client.rb +58 -3
- data/lib/cosmo/config.rb +13 -38
- data/lib/cosmo/engine.rb +1 -1
- data/lib/cosmo/job/processor.rb +66 -57
- data/lib/cosmo/job.rb +1 -1
- data/lib/cosmo/logger.rb +8 -1
- data/lib/cosmo/processor.rb +110 -2
- data/lib/cosmo/stream/processor.rb +23 -59
- data/lib/cosmo/stream.rb +2 -2
- data/lib/cosmo/utils/hash.rb +3 -27
- data/lib/cosmo/utils/overrides.rb +15 -0
- data/lib/cosmo/utils/ttl_cache.rb +44 -0
- data/lib/cosmo/utils/warnings.rb +17 -0
- data/lib/cosmo/utils.rb +15 -0
- data/lib/cosmo/version.rb +1 -1
- data/lib/cosmo/web/assets/app.css +477 -0
- data/lib/cosmo/web/assets/htmx.2.0.8.min.js.gz +0 -0
- data/lib/cosmo/web/context.rb +28 -0
- data/lib/cosmo/web/controllers/actions.rb +16 -0
- data/lib/cosmo/web/controllers/application.rb +43 -0
- data/lib/cosmo/web/controllers/jobs.rb +97 -0
- data/lib/cosmo/web/controllers/streams.rb +70 -0
- data/lib/cosmo/web/helpers/application.rb +87 -0
- data/lib/cosmo/web/renderer.rb +58 -0
- data/lib/cosmo/web/views/actions/index.erb +7 -0
- data/lib/cosmo/web/views/jobs/_busy.erb +50 -0
- data/lib/cosmo/web/views/jobs/_dead.erb +65 -0
- data/lib/cosmo/web/views/jobs/_enqueued.erb +60 -0
- data/lib/cosmo/web/views/jobs/_scheduled.erb +49 -0
- data/lib/cosmo/web/views/jobs/_stats.erb +69 -0
- data/lib/cosmo/web/views/jobs/busy.erb +16 -0
- data/lib/cosmo/web/views/jobs/dead.erb +17 -0
- data/lib/cosmo/web/views/jobs/enqueued.erb +16 -0
- data/lib/cosmo/web/views/jobs/index.erb +12 -0
- data/lib/cosmo/web/views/jobs/scheduled.erb +17 -0
- data/lib/cosmo/web/views/layout.erb +33 -0
- data/lib/cosmo/web/views/streams/_info.erb +92 -0
- data/lib/cosmo/web/views/streams/_pause_banner.erb +17 -0
- data/lib/cosmo/web/views/streams/_stream_row.erb +42 -0
- data/lib/cosmo/web/views/streams/_table.erb +25 -0
- data/lib/cosmo/web/views/streams/index.erb +11 -0
- data/lib/cosmo/web/views/streams/info.erb +11 -0
- data/lib/cosmo/web.rb +68 -0
- data/lib/cosmo.rb +2 -7
- data/sig/cosmo/api/busy.rbs +35 -0
- data/sig/cosmo/api/counter.rbs +34 -0
- data/sig/cosmo/api/job.rbs +31 -0
- data/sig/cosmo/api/kv.rbs +30 -0
- data/sig/cosmo/api/stats.rbs +21 -0
- data/sig/cosmo/api/stream.rbs +50 -0
- data/sig/cosmo/client.rbs +21 -3
- data/sig/cosmo/config.rbs +3 -15
- data/sig/cosmo/job/processor.rbs +16 -8
- data/sig/cosmo/processor.rbs +26 -0
- data/sig/cosmo/stream/processor.rbs +4 -10
- data/sig/cosmo/utils/hash.rbs +0 -8
- data/sig/cosmo/utils/ttl_cache.rbs +20 -0
- metadata +62 -3
- data/lib/cosmo/defaults.yml +0 -69
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<div class="cards-container">
|
|
2
|
+
<article class="stat-card">
|
|
3
|
+
<h3><%= format_numbers(@state.messages) %></h3>
|
|
4
|
+
<p>Messages</p>
|
|
5
|
+
</article>
|
|
6
|
+
<article class="stat-card">
|
|
7
|
+
<h3><%= format_bytes(@state.bytes) %></h3>
|
|
8
|
+
<p>Size</p>
|
|
9
|
+
</article>
|
|
10
|
+
<article class="stat-card">
|
|
11
|
+
<h3><%= @state.consumer_count %></h3>
|
|
12
|
+
<p>Consumers</p>
|
|
13
|
+
</article>
|
|
14
|
+
<article class="stat-card">
|
|
15
|
+
<h3><%= format_numbers(@state.first_seq) + " → " + format_numbers(@state.last_seq) %></h3>
|
|
16
|
+
<p>Sequence Range</p>
|
|
17
|
+
</article>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<%= render("streams/_pause_banner", { name: @name, paused: @paused }) %>
|
|
21
|
+
|
|
22
|
+
<div class="nav">
|
|
23
|
+
<a href="<%= url_for('/streams') %>"
|
|
24
|
+
hx-get="<%= url_for('/streams') %>"
|
|
25
|
+
hx-target="#content"
|
|
26
|
+
hx-push-url="true"
|
|
27
|
+
class="btn">Back to Streams</a>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<h2>Configuration</h2>
|
|
31
|
+
<div class="table-container">
|
|
32
|
+
<table>
|
|
33
|
+
<tbody>
|
|
34
|
+
<tr>
|
|
35
|
+
<th>Name</th>
|
|
36
|
+
<td>
|
|
37
|
+
<code><%= h(@name) %></code>
|
|
38
|
+
</td>
|
|
39
|
+
</tr>
|
|
40
|
+
<tr>
|
|
41
|
+
<th>Retention</th>
|
|
42
|
+
<td>
|
|
43
|
+
<code><%= h(@config.retention.to_s) %></code>
|
|
44
|
+
</td>
|
|
45
|
+
</tr>
|
|
46
|
+
<tr>
|
|
47
|
+
<th>Storage</th>
|
|
48
|
+
<td>
|
|
49
|
+
<code><%= h(@config.storage.to_s) %></code>
|
|
50
|
+
</td>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<th>Discard Policy</th>
|
|
54
|
+
<td>
|
|
55
|
+
<code><%= h(@config.discard.to_s) %></code>
|
|
56
|
+
</td>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<th>Max Consumers</th>
|
|
60
|
+
<td>
|
|
61
|
+
<code><%= @config.max_consumers || "Unlimited" %></code>
|
|
62
|
+
</td>
|
|
63
|
+
</tr>
|
|
64
|
+
<tr>
|
|
65
|
+
<th>Max Messages</th>
|
|
66
|
+
<td>
|
|
67
|
+
<code><%= @config.max_msgs || "Unlimited" %></code>
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<th>Max Bytes</th>
|
|
72
|
+
<td>
|
|
73
|
+
<code><%= @config.max_bytes&.positive? ? format_bytes(@config.max_bytes) : "Unlimited" %></code>
|
|
74
|
+
</td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr>
|
|
77
|
+
<th>Max Age</th>
|
|
78
|
+
<td>
|
|
79
|
+
<code><%= @config.max_age&.positive? ? "#{@config.max_age}ns" : "Unlimited" %></code>
|
|
80
|
+
</td>
|
|
81
|
+
</tr>
|
|
82
|
+
</tbody>
|
|
83
|
+
</table>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<h2>Subjects</h2>
|
|
87
|
+
<div class="subjects" style="margin-top: var(--space-2x);">
|
|
88
|
+
<% Array(@config.subjects).each do |sub| -%>
|
|
89
|
+
<div class="subject-tag" style="padding: var(--space) var(--space-2x); font-size: 1rem;"><%= h(sub) %></div>
|
|
90
|
+
<% end -%>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<% if @paused -%>
|
|
2
|
+
<div id="pause-banner-<%= h(@name) %>" class="alert alert-warning" style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:var(--space-2x);">
|
|
3
|
+
<span>⏸ <strong>Stream is paused</strong> — consumers are not fetching new messages.</span>
|
|
4
|
+
<a hx-patch="<%= url_for('/streams/unpause', { name: u(@name), banner: 1 }) %>"
|
|
5
|
+
hx-target="#pause-banner-<%= h(@name) %>"
|
|
6
|
+
hx-swap="outerHTML"
|
|
7
|
+
class="btn btn-success">▶ Resume Stream</a>
|
|
8
|
+
</div>
|
|
9
|
+
<% else -%>
|
|
10
|
+
<div id="pause-banner-<%= h(@name) %>" class="alert alert-success" style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:var(--space-2x);">
|
|
11
|
+
<span>▶ <strong>Stream is active</strong> — consumers are fetching new messages.</span>
|
|
12
|
+
<a hx-patch="<%= url_for('/streams/pause', { name: u(@name), banner: 1 }) %>"
|
|
13
|
+
hx-target="#pause-banner-<%= h(@name) %>"
|
|
14
|
+
hx-swap="outerHTML"
|
|
15
|
+
class="btn btn-warning">⏸ Pause Stream</a>
|
|
16
|
+
</div>
|
|
17
|
+
<% end -%>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<tr id="stream-row-<%= h(@stream[:name]) %>">
|
|
2
|
+
<td>
|
|
3
|
+
<a href="<%= url_for('/streams/info', { name: u(@stream[:name]) }) %>"
|
|
4
|
+
hx-get="<%= url_for('/streams/info', { name: u(@stream[:name]) }) %>"
|
|
5
|
+
hx-target="#content"
|
|
6
|
+
hx-push-url="true"
|
|
7
|
+
class="stream-link"><%= h(@stream[:name]) %></a>
|
|
8
|
+
</td>
|
|
9
|
+
<td><%= format_numbers(@stream[:messages]) %></td>
|
|
10
|
+
<td><%= format_bytes(@stream[:bytes]) %></td>
|
|
11
|
+
<td><%= @stream[:consumer_count] %></td>
|
|
12
|
+
<td>
|
|
13
|
+
<div class="subjects">
|
|
14
|
+
<% Array(@stream[:subjects]).each do |subject| -%>
|
|
15
|
+
<span class="subject-tag"><%= h(subject) %></span>
|
|
16
|
+
<% end -%>
|
|
17
|
+
</div>
|
|
18
|
+
</td>
|
|
19
|
+
<td><code><%= format_numbers(@stream[:first_seq]) %> → <%= format_numbers(@stream[:last_seq]) %></code></td>
|
|
20
|
+
<td>
|
|
21
|
+
<% if @stream[:paused] -%>
|
|
22
|
+
<span class="badge badge-warning">⏸ Paused</span>
|
|
23
|
+
<% elsif @stream[:consumer_count].to_i > 0 -%>
|
|
24
|
+
<span class="badge badge-success">▶ Active</span>
|
|
25
|
+
<% else -%>
|
|
26
|
+
<span class="badge">No consumers</span>
|
|
27
|
+
<% end -%>
|
|
28
|
+
</td>
|
|
29
|
+
<td>
|
|
30
|
+
<% if @stream[:paused] -%>
|
|
31
|
+
<a hx-patch="<%= url_for('/streams/unpause', { name: u(@stream[:name]) }) %>"
|
|
32
|
+
hx-target="#stream-row-<%= h(@stream[:name]) %>"
|
|
33
|
+
hx-swap="outerHTML"
|
|
34
|
+
class="btn btn-success">▶ Resume</a>
|
|
35
|
+
<% else -%>
|
|
36
|
+
<a hx-patch="<%= url_for('/streams/pause', { name: u(@stream[:name]) }) %>"
|
|
37
|
+
hx-target="#stream-row-<%= h(@stream[:name]) %>"
|
|
38
|
+
hx-swap="outerHTML"
|
|
39
|
+
class="btn btn-warning">⏸ Pause</a>
|
|
40
|
+
<% end -%>
|
|
41
|
+
</td>
|
|
42
|
+
</tr>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<% if @streams.empty? -%>
|
|
2
|
+
<div class="alert alert-info">No streams found</div>
|
|
3
|
+
<% else -%>
|
|
4
|
+
<div class="table-container">
|
|
5
|
+
<table>
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
<th>Name</th>
|
|
9
|
+
<th>Messages</th>
|
|
10
|
+
<th>Size</th>
|
|
11
|
+
<th>Consumers</th>
|
|
12
|
+
<th>Subjects</th>
|
|
13
|
+
<th>Sequence</th>
|
|
14
|
+
<th>Status</th>
|
|
15
|
+
<th>Actions</th>
|
|
16
|
+
</tr>
|
|
17
|
+
</thead>
|
|
18
|
+
<tbody>
|
|
19
|
+
<% @streams.each do |stream| -%>
|
|
20
|
+
<%= render("streams/_stream_row", { stream: stream }) %>
|
|
21
|
+
<% end -%>
|
|
22
|
+
</tbody>
|
|
23
|
+
</table>
|
|
24
|
+
</div>
|
|
25
|
+
<% end -%>
|
data/lib/cosmo/web.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rack"
|
|
4
|
+
require "json"
|
|
5
|
+
require "erb"
|
|
6
|
+
require "cosmo/web/context"
|
|
7
|
+
require "cosmo/web/renderer"
|
|
8
|
+
require "cosmo/web/controllers/application"
|
|
9
|
+
require "cosmo/web/controllers/jobs"
|
|
10
|
+
require "cosmo/web/controllers/streams"
|
|
11
|
+
require "cosmo/web/controllers/actions"
|
|
12
|
+
|
|
13
|
+
module Cosmo
|
|
14
|
+
class Web
|
|
15
|
+
include Renderer
|
|
16
|
+
|
|
17
|
+
def self.call(env)
|
|
18
|
+
new.call(env)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def call(env) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
22
|
+
@request = Rack::Request.new(env)
|
|
23
|
+
path = @request.path_info
|
|
24
|
+
method = @request.request_method
|
|
25
|
+
|
|
26
|
+
response = case [method.downcase.to_sym, path]
|
|
27
|
+
in [:get, "/"] then redirect_to("/jobs")
|
|
28
|
+
in [:get, "/jobs"] then [Controllers::Jobs, :index]
|
|
29
|
+
in [:get, "/jobs/scheduled"] then [Controllers::Jobs, :scheduled]
|
|
30
|
+
in [:get, "/jobs/dead"] then [Controllers::Jobs, :dead]
|
|
31
|
+
in [:get, "/jobs/busy"] then [Controllers::Jobs, :busy]
|
|
32
|
+
in [:get, "/jobs/enqueued"] then [Controllers::Jobs, :enqueued]
|
|
33
|
+
in [:patch, %r{/jobs/retry/\d+}] then [Controllers::Jobs, :retry]
|
|
34
|
+
in [:delete, %r{/jobs/delete/\d+}] then [Controllers::Jobs, :delete]
|
|
35
|
+
in [:get, "/jobs/_stats"] then [Controllers::Jobs, :_stats]
|
|
36
|
+
in [:get, "/jobs/_scheduled"] then [Controllers::Jobs, :_scheduled]
|
|
37
|
+
in [:get, "/jobs/_dead"] then [Controllers::Jobs, :_dead]
|
|
38
|
+
in [:get, "/jobs/_busy"] then [Controllers::Jobs, :_busy]
|
|
39
|
+
in [:get, "/jobs/_enqueued"] then [Controllers::Jobs, :_enqueued]
|
|
40
|
+
in [:get, "/streams"] then [Controllers::Streams, :index]
|
|
41
|
+
in [:get, "/streams/info"] then [Controllers::Streams, :info]
|
|
42
|
+
in [:get, "/streams/_table"] then [Controllers::Streams, :_table]
|
|
43
|
+
in [:get, "/streams/_info"] then [Controllers::Streams, :_info]
|
|
44
|
+
in [:patch, "/streams/pause"] then [Controllers::Streams, :pause]
|
|
45
|
+
in [:patch, "/streams/unpause"] then [Controllers::Streams, :unpause]
|
|
46
|
+
in [:get, "/actions"] then [Controllers::Actions, :index]
|
|
47
|
+
in [:get, "/assets/htmx.min.js.gz"] then serve("htmx.2.0.8.min.js.gz",
|
|
48
|
+
"application/javascript",
|
|
49
|
+
{ "content-encoding" => "gzip" })
|
|
50
|
+
in [:get, "/assets/app.css"] then serve("app.css", "text/css")
|
|
51
|
+
in [:get, "/favicon.ico"] then no_content
|
|
52
|
+
else not_found
|
|
53
|
+
end
|
|
54
|
+
handler(response)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def handler(response)
|
|
60
|
+
if response[0].is_a?(Class)
|
|
61
|
+
controller, action = response
|
|
62
|
+
return controller.new(@request).send(action)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
response
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
data/lib/cosmo.rb
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "cosmo/utils
|
|
4
|
-
require "cosmo/utils/json"
|
|
5
|
-
require "cosmo/utils/string"
|
|
6
|
-
require "cosmo/utils/signal"
|
|
7
|
-
require "cosmo/utils/stopwatch"
|
|
8
|
-
require "cosmo/utils/thread_pool"
|
|
9
|
-
|
|
3
|
+
require "cosmo/utils"
|
|
10
4
|
require "cosmo/client"
|
|
11
5
|
require "cosmo/publisher"
|
|
12
6
|
require "cosmo/processor"
|
|
@@ -17,6 +11,7 @@ require "cosmo/job"
|
|
|
17
11
|
require "cosmo/stream"
|
|
18
12
|
require "cosmo/cli"
|
|
19
13
|
require "cosmo/engine"
|
|
14
|
+
require "cosmo/api"
|
|
20
15
|
|
|
21
16
|
module Cosmo
|
|
22
17
|
class Error < StandardError; end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
class Busy
|
|
4
|
+
TTL: ::Integer
|
|
5
|
+
HEARTBEAT: ::Integer
|
|
6
|
+
BUCKET: ::String
|
|
7
|
+
|
|
8
|
+
self.@instance: Busy
|
|
9
|
+
@messages: Hash[::Integer, ::String]
|
|
10
|
+
@kv: KV
|
|
11
|
+
@thread: Thread?
|
|
12
|
+
@worker_id: ::String
|
|
13
|
+
|
|
14
|
+
def self.instance: () -> Busy
|
|
15
|
+
|
|
16
|
+
def initialize: () -> void
|
|
17
|
+
|
|
18
|
+
def with: (untyped message) { () -> void } -> void
|
|
19
|
+
|
|
20
|
+
def add: (untyped message) -> void
|
|
21
|
+
|
|
22
|
+
def delete: (untyped message) -> void
|
|
23
|
+
|
|
24
|
+
def list: (?limit: ::Integer) -> Array[Hash[Symbol, untyped]]
|
|
25
|
+
|
|
26
|
+
def size: () -> ::Integer
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def heartbeat_loop: () -> void
|
|
31
|
+
|
|
32
|
+
def worker_id: () -> ::String
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
class Counter
|
|
4
|
+
STREAM_NAME: ::String
|
|
5
|
+
|
|
6
|
+
self.@instance: Counter
|
|
7
|
+
@namespace: ::String
|
|
8
|
+
|
|
9
|
+
def self.instance: () -> Counter
|
|
10
|
+
|
|
11
|
+
def initialize: (::String namespace) -> void
|
|
12
|
+
|
|
13
|
+
def with: () { () -> bool } -> void
|
|
14
|
+
|
|
15
|
+
def increment: (Symbol key, ?by: ::Integer) -> ::Integer
|
|
16
|
+
alias incr increment
|
|
17
|
+
|
|
18
|
+
def decrement: (Symbol key, ?by: ::Integer) -> ::Integer
|
|
19
|
+
alias decr decrement
|
|
20
|
+
|
|
21
|
+
def reset: (Symbol key) -> untyped
|
|
22
|
+
|
|
23
|
+
def get: (Symbol key) -> ::Integer
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def publish: (Symbol key, ::String value) -> ::Integer
|
|
28
|
+
|
|
29
|
+
def subject: (Symbol key) -> ::String
|
|
30
|
+
|
|
31
|
+
def client: () -> Client
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
class Job
|
|
4
|
+
@stream: ::String
|
|
5
|
+
@message: untyped
|
|
6
|
+
@data: Hash[Symbol, untyped]?
|
|
7
|
+
|
|
8
|
+
attr_reader message: untyped
|
|
9
|
+
|
|
10
|
+
def initialize: (::String stream, untyped message) -> void
|
|
11
|
+
|
|
12
|
+
def data: () -> Hash[Symbol, untyped]?
|
|
13
|
+
|
|
14
|
+
def seq: () -> (::Integer | ::String)
|
|
15
|
+
|
|
16
|
+
def headers: () -> Hash[::String, ::String]?
|
|
17
|
+
|
|
18
|
+
def execute_at: () -> ::Integer?
|
|
19
|
+
|
|
20
|
+
def x_stream: () -> ::String?
|
|
21
|
+
|
|
22
|
+
def x_subject: () -> ::String?
|
|
23
|
+
|
|
24
|
+
def subject: () -> ::String
|
|
25
|
+
|
|
26
|
+
def stream: () -> ::String
|
|
27
|
+
|
|
28
|
+
def timestamp: () -> ::String?
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
class KV
|
|
4
|
+
@name: ::String
|
|
5
|
+
@options: Hash[Symbol, untyped]
|
|
6
|
+
@kv: untyped
|
|
7
|
+
|
|
8
|
+
def initialize: (::String name, ?Hash[Symbol, untyped]? options) -> void
|
|
9
|
+
|
|
10
|
+
def set: (::String | ::Integer key, ::String value) -> untyped
|
|
11
|
+
|
|
12
|
+
def get: (::String | ::Integer key) -> ::String?
|
|
13
|
+
|
|
14
|
+
def delete: (::String | ::Integer key) -> untyped
|
|
15
|
+
|
|
16
|
+
def keys: (?::String? subject, ?limit: ::Integer) -> Array[::String]
|
|
17
|
+
|
|
18
|
+
def purge: (::String | ::Integer key) -> untyped
|
|
19
|
+
|
|
20
|
+
def clean: () -> untyped
|
|
21
|
+
|
|
22
|
+
def count: () -> ::Integer
|
|
23
|
+
alias size count
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def kv: () -> untyped
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
module Stats
|
|
4
|
+
def self.summary: () -> Hash[Symbol, ::Integer]
|
|
5
|
+
|
|
6
|
+
def self.processed: () -> ::Integer
|
|
7
|
+
|
|
8
|
+
def self.failed: () -> ::Integer
|
|
9
|
+
|
|
10
|
+
def self.busy: () -> ::Integer
|
|
11
|
+
|
|
12
|
+
def self.enqueued: () -> ::Integer
|
|
13
|
+
|
|
14
|
+
def self.retries: () -> ::Integer
|
|
15
|
+
|
|
16
|
+
def self.scheduled: () -> ::Integer
|
|
17
|
+
|
|
18
|
+
def self.dead: () -> ::Integer
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Cosmo
|
|
2
|
+
module API
|
|
3
|
+
class Stream
|
|
4
|
+
LIMIT: ::Integer
|
|
5
|
+
|
|
6
|
+
self.@client: Client
|
|
7
|
+
@name: ::String
|
|
8
|
+
@offset: ::Integer
|
|
9
|
+
|
|
10
|
+
def self.all: () -> Array[Stream]
|
|
11
|
+
|
|
12
|
+
def self.jobs: () -> Array[Stream]
|
|
13
|
+
|
|
14
|
+
def self.client: () -> Client
|
|
15
|
+
|
|
16
|
+
attr_reader name: ::String
|
|
17
|
+
|
|
18
|
+
def initialize: (::String name) -> void
|
|
19
|
+
|
|
20
|
+
def info: () -> Hash[Symbol, untyped]
|
|
21
|
+
|
|
22
|
+
def offset: (::Integer) -> self
|
|
23
|
+
|
|
24
|
+
def total: () -> ::Integer
|
|
25
|
+
alias size total
|
|
26
|
+
|
|
27
|
+
def retries: () -> ::Integer
|
|
28
|
+
|
|
29
|
+
def each: () { (Job) -> void } -> void
|
|
30
|
+
|
|
31
|
+
def messages: (?page: ::Integer?, ?limit: ::Integer?) -> Array[Job]
|
|
32
|
+
|
|
33
|
+
def message: (::Integer seq) -> Job?
|
|
34
|
+
|
|
35
|
+
def retry: (::Integer seq) -> void
|
|
36
|
+
|
|
37
|
+
def delete: (::Integer seq) -> untyped
|
|
38
|
+
|
|
39
|
+
def pause!: () -> untyped
|
|
40
|
+
|
|
41
|
+
def unpause!: () -> untyped
|
|
42
|
+
|
|
43
|
+
def paused?: () -> bool
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def client: () -> Client
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/sig/cosmo/client.rbs
CHANGED
|
@@ -19,11 +19,29 @@ module Cosmo
|
|
|
19
19
|
|
|
20
20
|
def create_stream: (::String | Symbol name, Hash[Symbol, untyped] config) -> untyped
|
|
21
21
|
|
|
22
|
-
def delete_stream: (::String | Symbol name, Hash[Symbol, untyped] params) -> untyped
|
|
22
|
+
def delete_stream: (::String | Symbol name, ?Hash[Symbol, untyped] params) -> untyped
|
|
23
23
|
|
|
24
|
-
def
|
|
24
|
+
def update_stream: (::String | Symbol name, Hash[Symbol, untyped] config) -> untyped
|
|
25
25
|
|
|
26
|
-
def
|
|
26
|
+
def list_streams: () -> Array[Hash[::String, untyped]]
|
|
27
|
+
|
|
28
|
+
def pause_stream: (::String name) -> void
|
|
29
|
+
|
|
30
|
+
def unpause_stream: (::String name) -> void
|
|
31
|
+
|
|
32
|
+
def stream_paused?: (::String name) -> bool
|
|
33
|
+
|
|
34
|
+
def list_consumers: (::String stream_name) -> Array[Hash[::String, untyped]]
|
|
35
|
+
|
|
36
|
+
def consumer_info: (::String stream_name, ::String consumer_name) -> NATS::JetStream::API::ConsumerInfo
|
|
37
|
+
|
|
38
|
+
def get_message: (::String | Symbol name, **untyped options) -> NATS::JetStream::API::RawStreamMsg
|
|
39
|
+
|
|
40
|
+
def delete_message: (::String name, ::Integer seq) -> Hash[::String, untyped]
|
|
41
|
+
|
|
42
|
+
def purge: (::String stream_name, ::String? subject) -> ::Integer?
|
|
43
|
+
|
|
44
|
+
def kv: (::String name, **untyped opts) -> NATS::KeyValue
|
|
27
45
|
|
|
28
46
|
def close: -> void
|
|
29
47
|
end
|
data/sig/cosmo/config.rbs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
module Cosmo
|
|
2
|
-
class Config
|
|
2
|
+
class Config < ::Hash[Symbol, untyped]
|
|
3
3
|
NANO: Integer
|
|
4
4
|
DEFAULT_PATH: ::String
|
|
5
5
|
|
|
6
6
|
self.@instance: Config
|
|
7
|
-
self.@
|
|
8
|
-
@config: Hash[Symbol, untyped]?
|
|
9
|
-
@system: Hash[Symbol, untyped]
|
|
10
|
-
@defaults: Hash[Symbol, untyped]
|
|
7
|
+
self.@internal: Hash[Symbol, untyped]
|
|
11
8
|
|
|
12
9
|
def self.instance: () -> Config
|
|
13
10
|
|
|
14
|
-
def self.
|
|
11
|
+
def self.internal: () -> Hash[Symbol, untyped]
|
|
15
12
|
|
|
16
13
|
def self.parse_file: (::String path) -> Hash[Symbol, untyped]
|
|
17
14
|
|
|
@@ -31,15 +28,6 @@ module Cosmo
|
|
|
31
28
|
|
|
32
29
|
def self.load: (?::String? path) -> void
|
|
33
30
|
|
|
34
|
-
def initialize: () -> void
|
|
35
|
-
|
|
36
|
-
def []: (Symbol key) -> untyped
|
|
37
|
-
|
|
38
|
-
def fetch: (Symbol key, ?untyped default) -> untyped
|
|
39
|
-
|
|
40
|
-
def dig: (*Symbol keys) -> untyped
|
|
41
|
-
|
|
42
|
-
def to_h: () -> Hash[Symbol, untyped]
|
|
43
31
|
|
|
44
32
|
def set: (*untyped) -> untyped
|
|
45
33
|
|
data/sig/cosmo/job/processor.rbs
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
module Cosmo
|
|
2
2
|
module Job
|
|
3
3
|
class Processor < ::Cosmo::Processor
|
|
4
|
-
|
|
4
|
+
private
|
|
5
5
|
|
|
6
|
-
def
|
|
6
|
+
def setup: () -> void
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
def schedule_loop: () -> void
|
|
9
9
|
|
|
10
|
-
def
|
|
10
|
+
def scheduler?: () -> bool
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def consumers: () -> Array[untyped]
|
|
13
13
|
|
|
14
|
-
def
|
|
14
|
+
def fetch_subjects: (Hash[Symbol, untyped] config) -> untyped
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def fetch_timeout: (Hash[Symbol, untyped] config) -> Float
|
|
17
17
|
|
|
18
|
-
def process: (Array[untyped] messages) -> void
|
|
18
|
+
def process: (Array[untyped] messages, untyped processor) -> void
|
|
19
19
|
|
|
20
20
|
def handle_failure: (untyped message, Hash[Symbol, untyped] data) -> void
|
|
21
|
+
|
|
22
|
+
def subscribe: (Symbol stream_name, Hash[Symbol, untyped] config) -> [untyped, Hash[Symbol, untyped], nil]
|
|
23
|
+
|
|
24
|
+
def drop_message: (untyped message, Hash[Symbol, untyped] data) -> void
|
|
25
|
+
|
|
26
|
+
def move_message: (untyped message, ?Hash[Symbol, untyped]? data) -> void
|
|
27
|
+
|
|
28
|
+
def with_stats: (untyped message) { () -> untyped } -> void
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
data/sig/cosmo/processor.rbs
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
1
|
module Cosmo
|
|
2
2
|
class Processor
|
|
3
|
+
STREAM_PAUSED_RECHECK_TTL: Float
|
|
4
|
+
STREAMS_PAUSED_IDLE_SLEEP: Float
|
|
5
|
+
STREAM_EMPTY_BACKOFF_MAX: Float
|
|
6
|
+
|
|
3
7
|
@pool: Utils::ThreadPool
|
|
4
8
|
@running: untyped
|
|
5
9
|
@consumers: Array[untyped]
|
|
10
|
+
@threads: Array[Thread]
|
|
11
|
+
@cache: Utils::TTLCache
|
|
6
12
|
@options: Hash[Symbol, untyped]
|
|
13
|
+
@locks: Hash[::String, Mutex]
|
|
14
|
+
@consumer_state: untyped
|
|
7
15
|
|
|
8
16
|
def self.run: (*untyped) -> Processor
|
|
9
17
|
|
|
18
|
+
attr_reader consumers: Array[untyped]
|
|
19
|
+
|
|
10
20
|
def initialize: (Utils::ThreadPool pool, untyped running, Hash[Symbol, untyped] options) -> void
|
|
11
21
|
|
|
12
22
|
def run: () -> void
|
|
13
23
|
|
|
24
|
+
def stop: (?::Integer | ::Float timeout) -> void
|
|
25
|
+
|
|
14
26
|
private
|
|
15
27
|
|
|
16
28
|
def run_loop: () -> void
|
|
17
29
|
|
|
30
|
+
def work_loop: () -> void
|
|
31
|
+
|
|
32
|
+
def schedule_loop: () -> void
|
|
33
|
+
|
|
34
|
+
def scheduler?: () -> bool
|
|
35
|
+
|
|
18
36
|
def setup: () -> void
|
|
19
37
|
|
|
20
38
|
def process: (*untyped) -> void
|
|
21
39
|
|
|
40
|
+
def fetch_timeout: (Hash[Symbol, untyped] config) -> Float
|
|
41
|
+
|
|
42
|
+
def fetch_subjects: (Hash[Symbol, untyped] config) -> untyped
|
|
43
|
+
|
|
22
44
|
def running?: () -> bool
|
|
23
45
|
|
|
24
46
|
def fetch: (untyped subscription, batch_size: Integer, timeout: Float) ?{ (Array[untyped]) -> void } -> void
|
|
@@ -26,5 +48,9 @@ module Cosmo
|
|
|
26
48
|
def client: () -> Client
|
|
27
49
|
|
|
28
50
|
def stopwatch: () -> Utils::Stopwatch
|
|
51
|
+
|
|
52
|
+
def lock: (::String stream_name) { () -> void } -> void
|
|
53
|
+
|
|
54
|
+
def consumer_state: () -> untyped
|
|
29
55
|
end
|
|
30
56
|
end
|