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.
- checksums.yaml +4 -4
- data/README.md +54 -13
- data/lib/cosmo/active_job/adapter.rb +2 -0
- data/lib/cosmo/active_job/executor.rb +7 -0
- data/lib/cosmo/active_job/options.rb +6 -0
- data/lib/cosmo/api/batch.rb +26 -0
- data/lib/cosmo/api/counter.rb +51 -3
- data/lib/cosmo/api/cron/entry.rb +24 -9
- data/lib/cosmo/api/cron.rb +21 -7
- data/lib/cosmo/api/job.rb +14 -0
- data/lib/cosmo/api/kv.rb +138 -9
- data/lib/cosmo/api/registry.rb +47 -6
- data/lib/cosmo/api/stats/jobs.rb +84 -0
- data/lib/cosmo/api/stats/metrics.rb +18 -7
- data/lib/cosmo/api/stats/processes.rb +27 -11
- data/lib/cosmo/api/stats/totals.rb +1 -0
- data/lib/cosmo/api/stats.rb +47 -11
- data/lib/cosmo/api/stream.rb +66 -22
- data/lib/cosmo/batch/callback.rb +5 -0
- data/lib/cosmo/batch/dispatcher.rb +4 -4
- data/lib/cosmo/batch.rb +34 -11
- data/lib/cosmo/cli.rb +6 -0
- data/lib/cosmo/client.rb +208 -11
- data/lib/cosmo/config/cosmo.yml +1 -0
- data/lib/cosmo/config/settings.rb +4 -0
- data/lib/cosmo/config.rb +58 -10
- data/lib/cosmo/engine.rb +28 -1
- data/lib/cosmo/heartbeat.rb +12 -3
- data/lib/cosmo/http_server/handler.rb +5 -0
- data/lib/cosmo/http_server/health.rb +2 -0
- data/lib/cosmo/http_server/ping.rb +2 -0
- data/lib/cosmo/http_server.rb +8 -0
- data/lib/cosmo/job/data.rb +11 -0
- data/lib/cosmo/job/enqueuer.rb +100 -1
- data/lib/cosmo/job/limit.rb +5 -1
- data/lib/cosmo/job/processor.rb +51 -15
- data/lib/cosmo/job/setter.rb +53 -0
- data/lib/cosmo/job.rb +71 -2
- data/lib/cosmo/logger.rb +37 -0
- data/lib/cosmo/middleware/chain.rb +12 -0
- data/lib/cosmo/middleware/limit.rb +12 -3
- data/lib/cosmo/middleware/metrics.rb +6 -4
- data/lib/cosmo/middleware/sentry.rb +6 -4
- data/lib/cosmo/middleware/totals.rb +5 -11
- data/lib/cosmo/middleware.rb +0 -1
- data/lib/cosmo/processor.rb +60 -3
- data/lib/cosmo/publisher.rb +8 -0
- data/lib/cosmo/services.rb +7 -2
- data/lib/cosmo/stream/message.rb +5 -0
- data/lib/cosmo/stream/processor.rb +7 -0
- data/lib/cosmo/stream/serializer.rb +4 -0
- data/lib/cosmo/stream.rb +35 -1
- data/lib/cosmo/utils/duration.rb +3 -0
- data/lib/cosmo/utils/hash.rb +12 -0
- data/lib/cosmo/utils/json.rb +8 -0
- data/lib/cosmo/utils/signal.rb +9 -0
- data/lib/cosmo/utils/stopwatch.rb +1 -0
- data/lib/cosmo/utils/string.rb +4 -0
- data/lib/cosmo/utils/thread_pool.rb +8 -0
- data/lib/cosmo/utils/ttl_cache.rb +10 -0
- data/lib/cosmo/version.rb +1 -1
- data/lib/cosmo/web/assets/app.css +5 -3
- data/lib/cosmo/web/cache.rb +2 -0
- data/lib/cosmo/web/chart.rb +2 -2
- data/lib/cosmo/web/circuit.rb +1 -0
- data/lib/cosmo/web/context.rb +6 -0
- data/lib/cosmo/web/controllers/application.rb +26 -0
- data/lib/cosmo/web/controllers/batches.rb +7 -1
- data/lib/cosmo/web/controllers/crons.rb +16 -2
- data/lib/cosmo/web/controllers/jobs.rb +45 -16
- data/lib/cosmo/web/controllers/metrics.rb +5 -0
- data/lib/cosmo/web/controllers/overview.rb +36 -18
- data/lib/cosmo/web/controllers/processes.rb +8 -5
- data/lib/cosmo/web/controllers/streams.rb +12 -0
- data/lib/cosmo/web/helpers/application.rb +44 -0
- data/lib/cosmo/web/renderer.rb +17 -0
- data/lib/cosmo/web/throughput.rb +1 -1
- data/lib/cosmo/web/views/crons/_table.erb +29 -27
- data/lib/cosmo/web/views/jobs/_args.erb +2 -2
- data/lib/cosmo/web/views/jobs/_busy.erb +4 -4
- data/lib/cosmo/web/views/jobs/_enqueued.erb +2 -2
- data/lib/cosmo/web/views/jobs/_panel.erb +6 -1
- data/lib/cosmo/web/views/layout.erb +1 -1
- data/lib/cosmo/web/views/overview/_badges.erb +1 -1
- data/lib/cosmo/web/views/overview/_running.erb +3 -3
- data/lib/cosmo/web/views/overview/index.erb +1 -1
- data/lib/cosmo/web/views/streams/_info.erb +1 -0
- data/lib/cosmo/web/views/streams/_stream.erb +1 -0
- data/lib/cosmo/web.rb +8 -1
- data/lib/cosmo.rb +33 -0
- data/sig/cosmo/active_job/adapter.rbs +3 -3
- data/sig/cosmo/active_job/options.rbs +4 -2
- data/sig/cosmo/api/batch.rbs +5 -3
- data/sig/cosmo/api/counter.rbs +16 -6
- data/sig/cosmo/api/cron/entry.rbs +4 -2
- data/sig/cosmo/api/cron.rbs +10 -4
- data/sig/cosmo/api/kv.rbs +21 -4
- data/sig/cosmo/api/registry.rbs +10 -0
- data/sig/cosmo/api/stats/jobs.rbs +34 -0
- data/sig/cosmo/api/stats/metrics.rbs +3 -0
- data/sig/cosmo/api/stats/processes.rbs +9 -1
- data/sig/cosmo/api/stats.rbs +8 -2
- data/sig/cosmo/api/stream.rbs +10 -5
- data/sig/cosmo/batch/callback.rbs +1 -1
- data/sig/cosmo/batch/dispatcher.rbs +1 -1
- data/sig/cosmo/batch.rbs +5 -5
- data/sig/cosmo/cli.rbs +2 -0
- data/sig/cosmo/client.rbs +23 -4
- data/sig/cosmo/config/settings.rbs +6 -0
- data/sig/cosmo/config.rbs +5 -5
- data/sig/cosmo/engine.rbs +5 -0
- data/sig/cosmo/heartbeat.rbs +2 -0
- data/sig/cosmo/job/data.rbs +3 -1
- data/sig/cosmo/job/enqueuer.rbs +12 -0
- data/sig/cosmo/job/processor.rbs +18 -3
- data/sig/cosmo/job/setter.rbs +20 -0
- data/sig/cosmo/job.rbs +10 -4
- data/sig/cosmo/logger.rbs +5 -3
- data/sig/cosmo/middleware.rbs +0 -8
- data/sig/cosmo/processor.rbs +14 -2
- data/sig/cosmo/publisher.rbs +1 -0
- data/sig/cosmo/stream/processor.rbs +4 -0
- data/sig/cosmo/stream.rbs +4 -3
- data/sig/cosmo/utils/hash.rbs +2 -1
- data/sig/cosmo/utils/signal.rbs +5 -5
- data/sig/cosmo/utils/string.rbs +2 -2
- data/sig/cosmo/utils/thread_pool.rbs +1 -1
- data/sig/cosmo/web/cache.rbs +35 -0
- data/sig/cosmo/web/chart.rbs +48 -0
- data/sig/cosmo/web/circuit.rbs +29 -0
- data/sig/cosmo/web/context.rbs +15 -0
- data/sig/cosmo/web/controllers/application.rbs +32 -0
- data/sig/cosmo/web/controllers/batches.rbs +11 -0
- data/sig/cosmo/web/controllers/crons.rbs +23 -0
- data/sig/cosmo/web/controllers/jobs.rbs +47 -0
- data/sig/cosmo/web/controllers/metrics.rbs +21 -0
- data/sig/cosmo/web/controllers/overview.rbs +31 -0
- data/sig/cosmo/web/controllers/processes.rbs +13 -0
- data/sig/cosmo/web/controllers/streams.rbs +27 -0
- data/sig/cosmo/web/helpers/application.rbs +61 -0
- data/sig/cosmo/web/renderer.rbs +33 -0
- data/sig/cosmo/web/throughput.rbs +45 -0
- data/sig/cosmo/web.rbs +25 -0
- data/sig/cosmo.rbs +19 -0
- metadata +23 -6
- data/lib/cosmo/api/stats/busy.rb +0 -68
- data/lib/cosmo/middleware/busy.rb +0 -15
- data/sig/cosmo/api/stats/busy.rbs +0 -33
data/lib/cosmo/api/stream.rb
CHANGED
|
@@ -9,40 +9,53 @@ module Cosmo
|
|
|
9
9
|
|
|
10
10
|
include Enumerable
|
|
11
11
|
|
|
12
|
+
# @return [Array<Stream>] every stream, each answering #info from this one listing
|
|
12
13
|
def self.all
|
|
13
|
-
client.list_streams.map { new(_1.
|
|
14
|
+
client.list_streams.map { new(_1.config.name, _1) }
|
|
14
15
|
end
|
|
15
16
|
|
|
17
|
+
# @return [Array<Stream>] the job streams, each answering #info from this one listing
|
|
16
18
|
def self.jobs
|
|
17
|
-
client.list_streams.select { _1.
|
|
18
|
-
.reject { %w[scheduled dead].include?(_1.
|
|
19
|
-
.map { new(_1.
|
|
19
|
+
client.list_streams.select { _1.config.metadata&.[](:"_cosmo.type") == "jobs" }
|
|
20
|
+
.reject { %w[scheduled dead].include?(_1.config.name) }
|
|
21
|
+
.map { new(_1.config.name, _1) }
|
|
20
22
|
end
|
|
21
23
|
|
|
24
|
+
# @return [Client]
|
|
22
25
|
def self.client
|
|
23
26
|
@client ||= Client.instance
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
attr_reader :name
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
# @param name [String]
|
|
32
|
+
# @param info [NATS::JetStream::API::StreamInfo, nil] the stream's info from a listing, kept instead of fetched
|
|
33
|
+
def initialize(name, info = nil)
|
|
29
34
|
@name = name
|
|
35
|
+
@info = info
|
|
30
36
|
end
|
|
31
37
|
|
|
38
|
+
# @return [Hash] the stream's +:state+ and +:config+ as JetStream reports them, from the listing the stream
|
|
39
|
+
# came from or else fetched fresh on every call
|
|
32
40
|
def info
|
|
33
|
-
info = client.stream_info(name)
|
|
41
|
+
info = @info || client.stream_info(name)
|
|
34
42
|
{ state: info.state, config: info.config }
|
|
35
43
|
end
|
|
36
44
|
|
|
45
|
+
# @return [Integer] the stream's messages, not counting cron schedule templates; 0 when NATS can't be read
|
|
37
46
|
def total
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
state, config = info.values_at(:state, :config)
|
|
48
|
+
messages = state.messages.to_i
|
|
49
|
+
return messages unless Array(config.subjects).any? { _1.start_with?(Cron::Entry::SUBJECT_PREFIX) }
|
|
50
|
+
|
|
51
|
+
cron_count = client.cron_subjects_in_stream(name, "#{Cron::Entry::SUBJECT_PREFIX}.>").size
|
|
52
|
+
[messages - cron_count, 0].max
|
|
41
53
|
rescue NATS::Error
|
|
42
54
|
0
|
|
43
55
|
end
|
|
44
56
|
alias size total
|
|
45
57
|
|
|
58
|
+
# @return [Integer] redeliveries across the stream's consumers
|
|
46
59
|
def retries
|
|
47
60
|
consumers.sum { _1["num_redelivered"].to_i }
|
|
48
61
|
end
|
|
@@ -54,6 +67,10 @@ module Cosmo
|
|
|
54
67
|
[]
|
|
55
68
|
end
|
|
56
69
|
|
|
70
|
+
# Walks the stream's job messages in sequence order, from {#offset} or the first message.
|
|
71
|
+
#
|
|
72
|
+
# @yieldparam job [Job]
|
|
73
|
+
# @return [void]
|
|
57
74
|
def each
|
|
58
75
|
return if total.zero?
|
|
59
76
|
|
|
@@ -73,26 +90,27 @@ module Cosmo
|
|
|
73
90
|
end
|
|
74
91
|
end
|
|
75
92
|
|
|
93
|
+
# Sets the sequence {#each} starts at.
|
|
94
|
+
#
|
|
95
|
+
# @param value [Integer]
|
|
96
|
+
# @return [self]
|
|
76
97
|
def offset(value)
|
|
77
98
|
@offset = value.to_i
|
|
78
99
|
self
|
|
79
100
|
end
|
|
80
101
|
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
# @param page [Integer, nil] 1-based page, counted in sequences from the first message (or the last, for +:desc+)
|
|
103
|
+
# @param limit [Integer, nil] jobs per page, {LIMIT} when nil
|
|
104
|
+
# @param order [Symbol] +:asc+ for oldest first, +:desc+ for newest first
|
|
105
|
+
# @return [Array<Job>]
|
|
106
|
+
def messages(page: nil, limit: nil, order: :asc)
|
|
83
107
|
limit = (limit || LIMIT).to_i
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
start += (page.to_i - 1) * limit if page
|
|
87
|
-
|
|
88
|
-
offset(start).each do |message|
|
|
89
|
-
jobs << message
|
|
90
|
-
break if jobs.size >= limit
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
jobs
|
|
108
|
+
page = [page.to_i, 1].max
|
|
109
|
+
order == :desc ? messages_desc(page, limit) : messages_asc(page, limit)
|
|
94
110
|
end
|
|
95
111
|
|
|
112
|
+
# @param seq [Integer]
|
|
113
|
+
# @return [Job, nil] nil when the message is gone or is a cron schedule template
|
|
96
114
|
def message(seq)
|
|
97
115
|
job = Job.new(name, client.get_message(name, seq: seq, direct: true))
|
|
98
116
|
return if job.subject.to_s.start_with?(Cron::Entry::SUBJECT_PREFIX)
|
|
@@ -102,6 +120,10 @@ module Cosmo
|
|
|
102
120
|
# nop, acked/nacked
|
|
103
121
|
end
|
|
104
122
|
|
|
123
|
+
# Republishes the job at +seq+ to its +X-Subject+ and deletes it here.
|
|
124
|
+
#
|
|
125
|
+
# @param seq [Integer]
|
|
126
|
+
# @return [void]
|
|
105
127
|
def retry(seq)
|
|
106
128
|
job = message(seq)
|
|
107
129
|
return unless job
|
|
@@ -110,24 +132,46 @@ module Cosmo
|
|
|
110
132
|
delete(seq)
|
|
111
133
|
end
|
|
112
134
|
|
|
135
|
+
# @param seq [Integer]
|
|
136
|
+
# @return [Hash] the JetStream API response
|
|
113
137
|
def delete(seq)
|
|
114
138
|
client.delete_message(name, seq)
|
|
115
139
|
end
|
|
116
140
|
|
|
141
|
+
# Marks the stream paused, so workers stop fetching from it.
|
|
142
|
+
#
|
|
143
|
+
# @return [void]
|
|
117
144
|
def pause!
|
|
118
145
|
client.pause_stream(name)
|
|
119
146
|
end
|
|
120
147
|
|
|
148
|
+
# @return [void]
|
|
121
149
|
def unpause!
|
|
122
150
|
client.unpause_stream(name)
|
|
123
151
|
end
|
|
124
152
|
|
|
153
|
+
# @return [Boolean] false when the server doesn't answer in time
|
|
125
154
|
def paused?
|
|
126
|
-
|
|
155
|
+
info[:config].metadata&.[](:"_cosmo.paused") == "true"
|
|
156
|
+
rescue NATS::IO::Timeout
|
|
157
|
+
false
|
|
127
158
|
end
|
|
128
159
|
|
|
129
160
|
private
|
|
130
161
|
|
|
162
|
+
# Page +page+ holds the first +limit+ jobs from +(page - 1) * limit+ sequences after the first one.
|
|
163
|
+
def messages_asc(page, limit)
|
|
164
|
+
offset(info[:state].first_seq.to_i + ((page - 1) * limit)).first(limit)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Page +page+ covers the +limit+ sequences ending +(page - 1) * limit+ below the last one, read forward and
|
|
168
|
+
# reversed, as direct gets can't walk a stream backwards.
|
|
169
|
+
def messages_desc(page, limit)
|
|
170
|
+
state = info[:state]
|
|
171
|
+
upto = state.last_seq.to_i - ((page - 1) * limit)
|
|
172
|
+
offset([upto - limit + 1, state.first_seq.to_i].max).take_while { _1.seq.to_i <= upto }.reverse
|
|
173
|
+
end
|
|
174
|
+
|
|
131
175
|
def scan_range
|
|
132
176
|
data = info
|
|
133
177
|
state = data[:state]
|
data/lib/cosmo/batch/callback.rb
CHANGED
|
@@ -8,6 +8,11 @@ module Cosmo
|
|
|
8
8
|
class Callback
|
|
9
9
|
include Cosmo::Job
|
|
10
10
|
|
|
11
|
+
# @param class_name [String] the class given to {Batch#on}
|
|
12
|
+
# @param event [String, Symbol] +success+ or +complete+
|
|
13
|
+
# @param status [Hash] +bid+, +total+, +succeeded+, and +failed+
|
|
14
|
+
# @param opts [Hash] the options given to {Batch#on}
|
|
15
|
+
# @return [void]
|
|
11
16
|
def perform(class_name, event, status, opts)
|
|
12
17
|
klass = Utils::String.safe_constantize(class_name)
|
|
13
18
|
klass&.new&.public_send("on_#{event}", status, opts)
|
|
@@ -11,8 +11,8 @@ module Cosmo
|
|
|
11
11
|
# finalize the batch. This never touches total or failed - that's what
|
|
12
12
|
# lets #jobs release its placeholder slot without messing up the stats
|
|
13
13
|
# we report back.
|
|
14
|
-
def release_pending(bid, msg_id: nil)
|
|
15
|
-
pending = counter.decrement("#{bid}.pending", msg_id: msg_id)
|
|
14
|
+
def release_pending(bid, by: 1, msg_id: nil)
|
|
15
|
+
pending = counter.decrement!("#{bid}.pending", by: by, msg_id: msg_id)
|
|
16
16
|
finalize(bid) if pending.to_i.zero?
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -51,8 +51,8 @@ module Cosmo
|
|
|
51
51
|
|
|
52
52
|
# Adds this batch as one job of the parent batch.
|
|
53
53
|
def link(parent_id)
|
|
54
|
-
counter.increment("#{parent_id}.total")
|
|
55
|
-
counter.increment("#{parent_id}.pending")
|
|
54
|
+
counter.increment!("#{parent_id}.total")
|
|
55
|
+
counter.increment!("#{parent_id}.pending")
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
# Fires the callback for +event+, if one is registered and the batch is
|
data/lib/cosmo/batch.rb
CHANGED
|
@@ -87,6 +87,7 @@ module Cosmo
|
|
|
87
87
|
BUCKET = "_cosmobatches"
|
|
88
88
|
EVENTS = %i[success complete].freeze
|
|
89
89
|
|
|
90
|
+
# @return [Batch, nil] the batch whose #jobs block runs on this thread
|
|
90
91
|
def self.current
|
|
91
92
|
Thread.current[:cosmo_batch]
|
|
92
93
|
end
|
|
@@ -94,17 +95,24 @@ module Cosmo
|
|
|
94
95
|
# Called by Job::Processor when a job is done for good - acked, or
|
|
95
96
|
# dead-lettered/dropped. Never call this for a retry. JID is used to dedupe: if the same
|
|
96
97
|
# job's ack gets lost, and it's redelivered, we don't want to count it twice.
|
|
98
|
+
#
|
|
99
|
+
# @param bid [String]
|
|
100
|
+
# @param jid [String]
|
|
101
|
+
# @param success [Boolean] false when the job was dead-lettered or dropped
|
|
102
|
+
# @return [void]
|
|
97
103
|
def self.notify(bid, jid, success:)
|
|
98
|
-
counter.increment("#{bid}.failed", msg_id: "batch.#{bid}.#{jid}.failed") unless success
|
|
104
|
+
counter.increment!("#{bid}.failed", msg_id: "batch.#{bid}.#{jid}.failed") unless success
|
|
99
105
|
release_pending(bid, msg_id: "batch.#{bid}.#{jid}.pending")
|
|
100
106
|
end
|
|
101
107
|
|
|
108
|
+
# @return [Counters]
|
|
102
109
|
def self.counter
|
|
103
110
|
@counter ||= Counters.new("batch")
|
|
104
111
|
end
|
|
105
112
|
|
|
113
|
+
# @return [API::KV] the bucket holding every batch's metadata, callbacks, and results
|
|
106
114
|
def self.kv
|
|
107
|
-
@kv ||= API::KV.new(BUCKET, ttl: Utils::Duration.parse(Config.batches.expiry), replicas: Config.
|
|
115
|
+
@kv ||= API::KV.new(BUCKET, ttl: Utils::Duration.parse(Config.batches.expiry), replicas: Config.services.num_replicas)
|
|
108
116
|
end
|
|
109
117
|
|
|
110
118
|
attr_reader :bid, :parent_id
|
|
@@ -123,10 +131,13 @@ module Cosmo
|
|
|
123
131
|
# toward total, so it doesn't skew the stats. Safe to call more than
|
|
124
132
|
# once. If the block raises, we still release the placeholder (so the
|
|
125
133
|
# batch isn't stuck) and let the error propagate as normal.
|
|
134
|
+
#
|
|
135
|
+
# @yieldreturn [Object]
|
|
136
|
+
# @return [Object] the block's result
|
|
126
137
|
def jobs
|
|
127
138
|
previous = Thread.current[:cosmo_batch]
|
|
128
139
|
Thread.current[:cosmo_batch] = self
|
|
129
|
-
counter.increment("#{bid}.pending")
|
|
140
|
+
counter.increment!("#{bid}.pending")
|
|
130
141
|
begin
|
|
131
142
|
yield
|
|
132
143
|
ensure
|
|
@@ -138,6 +149,12 @@ module Cosmo
|
|
|
138
149
|
# Registers a callback for +event+ (:success or :complete). Can be
|
|
139
150
|
# called before or after #jobs - if the batch already finished, it
|
|
140
151
|
# fires right away.
|
|
152
|
+
#
|
|
153
|
+
# @param event [Symbol] +:success+ or +:complete+
|
|
154
|
+
# @param klass [Class] a class whose instances respond to +on_success+/+on_complete+ with +(status, options)+
|
|
155
|
+
# @param opts [Hash] passed to the callback as +options+
|
|
156
|
+
# @return [void]
|
|
157
|
+
# @raise [ArgumentError] for any other event
|
|
141
158
|
def on(event, klass, **opts)
|
|
142
159
|
raise ArgumentError, "event must be :success or :complete" unless EVENTS.include?(event)
|
|
143
160
|
|
|
@@ -145,18 +162,24 @@ module Cosmo
|
|
|
145
162
|
try_fire(event)
|
|
146
163
|
end
|
|
147
164
|
|
|
148
|
-
# Called by Job#perform for each job added inside #jobs.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
165
|
+
# Called by Job#perform for each job added inside #jobs, and once per chunk by perform_bulk.
|
|
166
|
+
# @param count [Integer] how many jobs join the batch
|
|
167
|
+
# @return [void]
|
|
168
|
+
def register_job!(count = 1)
|
|
169
|
+
counter.increment!("#{bid}.total", by: count)
|
|
170
|
+
counter.increment!("#{bid}.pending", by: count)
|
|
152
171
|
end
|
|
153
172
|
|
|
154
173
|
# Undoes #register_job! when the publish itself failed, so the job
|
|
155
174
|
# never really joined the batch. Unlike a real completion, this also
|
|
156
175
|
# reverts total, not just pending.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
# @param count [Integer] how many registered jobs were not published
|
|
177
|
+
# @return [void]
|
|
178
|
+
def rollback_job!(count = 1)
|
|
179
|
+
return unless count.positive?
|
|
180
|
+
|
|
181
|
+
counter.decrement!("#{bid}.total", by: count)
|
|
182
|
+
release_pending(count)
|
|
160
183
|
end
|
|
161
184
|
|
|
162
185
|
private
|
|
@@ -165,7 +188,7 @@ module Cosmo
|
|
|
165
188
|
def counter = self.class.counter
|
|
166
189
|
def kv = self.class.kv
|
|
167
190
|
def link(parent_id) = self.class.send(:link, parent_id)
|
|
168
|
-
def release_pending = self.class.send(:release_pending, bid)
|
|
191
|
+
def release_pending(count = 1) = self.class.send(:release_pending, bid, by: count)
|
|
169
192
|
def try_fire(event) = self.class.send(:try_fire, bid, event)
|
|
170
193
|
end
|
|
171
194
|
end
|
data/lib/cosmo/cli.rb
CHANGED
|
@@ -7,10 +7,12 @@ require "fileutils"
|
|
|
7
7
|
module Cosmo
|
|
8
8
|
# rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/BlockLength
|
|
9
9
|
class CLI
|
|
10
|
+
# @return [void]
|
|
10
11
|
def self.run
|
|
11
12
|
instance.run
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
# @return [CLI]
|
|
14
16
|
def self.instance
|
|
15
17
|
@instance ||= new
|
|
16
18
|
end
|
|
@@ -18,6 +20,9 @@ module Cosmo
|
|
|
18
20
|
# @return [Array<String>, nil] the arguments the process was started with, before parsing consumed them
|
|
19
21
|
attr_reader :argv
|
|
20
22
|
|
|
23
|
+
# Parses the command line, then runs +--init+ or +--setup+, or loads the config and the app and starts the {Engine}.
|
|
24
|
+
#
|
|
25
|
+
# @return [void]
|
|
21
26
|
def run
|
|
22
27
|
@argv = ARGV.dup
|
|
23
28
|
flags, command, options = parse
|
|
@@ -252,6 +257,7 @@ module Cosmo
|
|
|
252
257
|
require path
|
|
253
258
|
end
|
|
254
259
|
|
|
260
|
+
# @return [String] the logo printed on start
|
|
255
261
|
# rubocop:disable-next Layout/TrailingWhitespace,Lint/IneffectiveAccessModifier
|
|
256
262
|
def self.banner
|
|
257
263
|
<<-TEXT
|