robin 0.0.4 → 0.1.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 +7 -0
- data/CHANGELOG.md +372 -0
- data/COPYING +674 -0
- data/LICENSE +165 -0
- data/README.md +1490 -0
- data/assets/favicon.svg +31 -0
- data/assets/robin-logo.svg +37 -0
- data/assets/robin-mono.svg +12 -0
- data/assets/robin-wordmark.svg +4 -0
- data/assets/robin.svg +34 -0
- data/exe/robin +5 -0
- data/ext/robin_resp/extconf.rb +29 -0
- data/ext/robin_resp/robin_resp.c +645 -0
- data/lib/active_job/queue_adapters/robin_adapter.rb +3 -0
- data/lib/generators/robin/install/install_generator.rb +39 -0
- data/lib/generators/robin/install/templates/initializer.rb.tt +31 -0
- data/lib/generators/robin/install/templates/robin.yml.tt +25 -0
- data/lib/generators/robin/job/job_generator.rb +78 -0
- data/lib/generators/robin/job/templates/job.rb.tt +13 -0
- data/lib/generators/robin/job/templates/job_spec.rb.tt +21 -0
- data/lib/generators/robin/job/templates/job_test.rb.tt +21 -0
- data/lib/puma/plugin/robin.rb +131 -0
- data/lib/robin/active_job.rb +144 -0
- data/lib/robin/api.rb +777 -0
- data/lib/robin/batch.rb +700 -0
- data/lib/robin/cancellation.rb +62 -0
- data/lib/robin/cli.rb +325 -0
- data/lib/robin/client.rb +355 -21
- data/lib/robin/config.rb +454 -4
- data/lib/robin/cron.rb +325 -0
- data/lib/robin/debounce.rb +108 -0
- data/lib/robin/deploy.rb +65 -0
- data/lib/robin/embedded.rb +53 -0
- data/lib/robin/encryption.rb +147 -0
- data/lib/robin/events.rb +60 -0
- data/lib/robin/expiry.rb +41 -0
- data/lib/robin/fetcher.rb +441 -0
- data/lib/robin/gvl.rb +62 -0
- data/lib/robin/health.rb +76 -0
- data/lib/robin/iterable_job.rb +294 -0
- data/lib/robin/job.rb +258 -0
- data/lib/robin/job_class.rb +157 -0
- data/lib/robin/job_logger.rb +121 -0
- data/lib/robin/launcher.rb +658 -0
- data/lib/robin/leader.rb +86 -0
- data/lib/robin/limiter.rb +639 -0
- data/lib/robin/manager.rb +125 -0
- data/lib/robin/metrics.rb +303 -0
- data/lib/robin/middleware.rb +165 -0
- data/lib/robin/opentelemetry.rb +88 -0
- data/lib/robin/periodic.rb +327 -0
- data/lib/robin/processor.rb +317 -0
- data/lib/robin/profiler.rb +140 -0
- data/lib/robin/progress.rb +46 -0
- data/lib/robin/rails/app_loader.rb +23 -0
- data/lib/robin/rails/current_attributes.rb +88 -0
- data/lib/robin/rails/error_reporter.rb +31 -0
- data/lib/robin/rails/notifications.rb +22 -0
- data/lib/robin/rails/railtie.rb +87 -0
- data/lib/robin/rails/transactional_push.rb +49 -0
- data/lib/robin/rails.rb +23 -0
- data/lib/robin/recovery.rb +135 -0
- data/lib/robin/redis/connection.rb +639 -0
- data/lib/robin/redis/pool.rb +190 -0
- data/lib/robin/redis/resp.rb +77 -0
- data/lib/robin/reliable_push.rb +153 -0
- data/lib/robin/retrier.rb +284 -0
- data/lib/robin/scheduler.rb +102 -0
- data/lib/robin/scripts.rb +331 -0
- data/lib/robin/statsd.rb +135 -0
- data/lib/robin/swarm.rb +319 -0
- data/lib/robin/systemd.rb +47 -0
- data/lib/robin/testing.rb +158 -0
- data/lib/robin/top.rb +178 -0
- data/lib/robin/unique.rb +198 -0
- data/lib/robin/version.rb +5 -0
- data/lib/robin/warmup.rb +94 -0
- data/lib/robin/web/api.rb +580 -0
- data/lib/robin/web/batch_status.rb +44 -0
- data/lib/robin/web/dist/assets/ar-y7v9b75f.js +1 -0
- data/lib/robin/web/dist/assets/ar-y7v9b75f.js.gz +0 -0
- data/lib/robin/web/dist/assets/bricolage-0qmzcpnj.woff2 +0 -0
- data/lib/robin/web/dist/assets/cs-df88mq5e.js +1 -0
- data/lib/robin/web/dist/assets/cs-df88mq5e.js.gz +0 -0
- data/lib/robin/web/dist/assets/da-kemms74g.js +1 -0
- data/lib/robin/web/dist/assets/da-kemms74g.js.gz +0 -0
- data/lib/robin/web/dist/assets/de-z8kkqg65.js +1 -0
- data/lib/robin/web/dist/assets/de-z8kkqg65.js.gz +0 -0
- data/lib/robin/web/dist/assets/es-9ahrrn1s.js +1 -0
- data/lib/robin/web/dist/assets/es-9ahrrn1s.js.gz +0 -0
- data/lib/robin/web/dist/assets/fa-7r0x28nc.js +1 -0
- data/lib/robin/web/dist/assets/fa-7r0x28nc.js.gz +0 -0
- data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg +31 -0
- data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg.gz +0 -0
- data/lib/robin/web/dist/assets/fr-r7mqf3d9.js +1 -0
- data/lib/robin/web/dist/assets/fr-r7mqf3d9.js.gz +0 -0
- data/lib/robin/web/dist/assets/he-7t46b6rt.js +1 -0
- data/lib/robin/web/dist/assets/he-7t46b6rt.js.gz +0 -0
- data/lib/robin/web/dist/assets/hi-zj434tx4.js +1 -0
- data/lib/robin/web/dist/assets/hi-zj434tx4.js.gz +0 -0
- data/lib/robin/web/dist/assets/it-pqc2m7gm.js +1 -0
- data/lib/robin/web/dist/assets/it-pqc2m7gm.js.gz +0 -0
- data/lib/robin/web/dist/assets/ja-k9rgm1pj.js +1 -0
- data/lib/robin/web/dist/assets/ja-k9rgm1pj.js.gz +0 -0
- data/lib/robin/web/dist/assets/ko-bxersv91.js +1 -0
- data/lib/robin/web/dist/assets/ko-bxersv91.js.gz +0 -0
- data/lib/robin/web/dist/assets/main-anw3f6ba.css +1 -0
- data/lib/robin/web/dist/assets/main-anw3f6ba.css.gz +0 -0
- data/lib/robin/web/dist/assets/main-pdtvjejb.js +7 -0
- data/lib/robin/web/dist/assets/main-pdtvjejb.js.gz +0 -0
- data/lib/robin/web/dist/assets/main-zz8zzhwn.js +2 -0
- data/lib/robin/web/dist/assets/main-zz8zzhwn.js.gz +0 -0
- data/lib/robin/web/dist/assets/nb-fjnc5064.js +1 -0
- data/lib/robin/web/dist/assets/nb-fjnc5064.js.gz +0 -0
- data/lib/robin/web/dist/assets/nl-9p8b95b6.js +1 -0
- data/lib/robin/web/dist/assets/nl-9p8b95b6.js.gz +0 -0
- data/lib/robin/web/dist/assets/pl-8xsrdn8n.js +1 -0
- data/lib/robin/web/dist/assets/pl-8xsrdn8n.js.gz +0 -0
- data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js +1 -0
- data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js.gz +0 -0
- data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg +34 -0
- data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg.gz +0 -0
- data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg +4 -0
- data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg.gz +0 -0
- data/lib/robin/web/dist/assets/ru-a9ftyw3d.js +1 -0
- data/lib/robin/web/dist/assets/ru-a9ftyw3d.js.gz +0 -0
- data/lib/robin/web/dist/assets/sv-j9gqamr1.js +1 -0
- data/lib/robin/web/dist/assets/sv-j9gqamr1.js.gz +0 -0
- data/lib/robin/web/dist/assets/tr-y9z0q51g.js +1 -0
- data/lib/robin/web/dist/assets/tr-y9z0q51g.js.gz +0 -0
- data/lib/robin/web/dist/assets/uk-2dr9ew3p.js +1 -0
- data/lib/robin/web/dist/assets/uk-2dr9ew3p.js.gz +0 -0
- data/lib/robin/web/dist/assets/ur-h25nzq1s.js +1 -0
- data/lib/robin/web/dist/assets/ur-h25nzq1s.js.gz +0 -0
- data/lib/robin/web/dist/assets/vi-9y2ff1bd.js +1 -0
- data/lib/robin/web/dist/assets/vi-9y2ff1bd.js.gz +0 -0
- data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js +1 -0
- data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js.gz +0 -0
- data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js +1 -0
- data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js.gz +0 -0
- data/lib/robin/web/dist/index.html +19 -0
- data/lib/robin/web/extension.rb +193 -0
- data/lib/robin/web/permissions.rb +40 -0
- data/lib/robin/web/prometheus.rb +79 -0
- data/lib/robin/web/router.rb +150 -0
- data/lib/robin/web/static.rb +110 -0
- data/lib/robin/web.rb +196 -0
- data/lib/robin.rb +258 -8
- data/sig/manifest.yaml +9 -0
- data/sig/robin/api.rbs +442 -0
- data/sig/robin/batch.rbs +292 -0
- data/sig/robin/cancellation.rbs +25 -0
- data/sig/robin/cli.rbs +102 -0
- data/sig/robin/client.rbs +118 -0
- data/sig/robin/config.rbs +341 -0
- data/sig/robin/cron.rbs +149 -0
- data/sig/robin/debounce.rbs +36 -0
- data/sig/robin/deploy.rbs +24 -0
- data/sig/robin/embedded.rbs +25 -0
- data/sig/robin/encryption.rbs +49 -0
- data/sig/robin/events.rbs +10 -0
- data/sig/robin/expiry.rbs +17 -0
- data/sig/robin/fetcher.rbs +134 -0
- data/sig/robin/gvl.rbs +39 -0
- data/sig/robin/health.rbs +30 -0
- data/sig/robin/iterable_job.rbs +99 -0
- data/sig/robin/job.rbs +173 -0
- data/sig/robin/job_class.rbs +55 -0
- data/sig/robin/job_logger.rbs +56 -0
- data/sig/robin/launcher.rbs +191 -0
- data/sig/robin/leader.rbs +43 -0
- data/sig/robin/limiter.rbs +317 -0
- data/sig/robin/manager.rbs +54 -0
- data/sig/robin/metrics.rbs +122 -0
- data/sig/robin/middleware.rbs +106 -0
- data/sig/robin/opentelemetry.rbs +51 -0
- data/sig/robin/periodic.rbs +81 -0
- data/sig/robin/processor.rbs +107 -0
- data/sig/robin/profiler.rbs +60 -0
- data/sig/robin/progress.rbs +22 -0
- data/sig/robin/rails/app_loader.rbs +10 -0
- data/sig/robin/rails/current_attributes.rbs +44 -0
- data/sig/robin/rails/error_reporter.rbs +21 -0
- data/sig/robin/rails/notifications.rbs +9 -0
- data/sig/robin/rails/transactional_push.rbs +16 -0
- data/sig/robin/rails.rbs +8 -0
- data/sig/robin/recovery.rbs +29 -0
- data/sig/robin/redis/connection.rbs +224 -0
- data/sig/robin/redis/pool.rbs +89 -0
- data/sig/robin/redis/resp.rbs +29 -0
- data/sig/robin/reliable_push.rbs +77 -0
- data/sig/robin/retrier.rbs +72 -0
- data/sig/robin/scheduler.rbs +40 -0
- data/sig/robin/scripts.rbs +36 -0
- data/sig/robin/statsd.rbs +55 -0
- data/sig/robin/swarm.rbs +133 -0
- data/sig/robin/systemd.rbs +13 -0
- data/sig/robin/testing.rbs +80 -0
- data/sig/robin/top.rbs +79 -0
- data/sig/robin/unique.rbs +72 -0
- data/sig/robin/version.rbs +3 -0
- data/sig/robin/warmup.rbs +44 -0
- data/sig/robin/web/api.rbs +196 -0
- data/sig/robin/web/batch_status.rbs +25 -0
- data/sig/robin/web/extension.rbs +106 -0
- data/sig/robin/web/permissions.rbs +14 -0
- data/sig/robin/web/prometheus.rbs +33 -0
- data/sig/robin/web/router.rbs +53 -0
- data/sig/robin/web/static.rbs +42 -0
- data/sig/robin/web.rbs +140 -0
- data/sig/robin.rbs +116 -0
- data/sig/robin_resp.rbs +55 -0
- metadata +274 -44
- data/bin/robin +0 -5
- data/lib/robin/actions/authenticate.rb +0 -38
- data/lib/robin/actions/empty_tweet.rb +0 -7
- data/lib/robin/actions/followers.rb +0 -22
- data/lib/robin/actions/help.rb +0 -16
- data/lib/robin/actions/home_timeline.rb +0 -9
- data/lib/robin/actions/new_tweet.rb +0 -11
- data/lib/robin/actions/unknown_flag.rb +0 -11
- data/lib/robin/actions/user_timeline.rb +0 -19
- data/lib/robin/args_parser.rb +0 -70
- data/lib/robin/pin_authenticator.rb +0 -31
- data/lib/robin/user.rb +0 -36
data/sig/robin/batch.rbs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# A group of jobs tracked as a unit, with callbacks (:complete, :success,
|
|
3
|
+
# :death) when the group is done.
|
|
4
|
+
#
|
|
5
|
+
# batch = Robin::Batch.new
|
|
6
|
+
# batch.on(:success, ImportCallbacks, "file_id" => file.id)
|
|
7
|
+
# batch.jobs { rows.each { |r| ImportRow.perform_async(r) } }
|
|
8
|
+
class Batch
|
|
9
|
+
class NoSuchBatch < Robin::Error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# A member of a batch: a jid, or "batch:<bid>" for a child batch.
|
|
13
|
+
type member = String
|
|
14
|
+
|
|
15
|
+
# Where batch commands go: a connection (which replies), or a pipeline
|
|
16
|
+
# or transaction to queue them in.
|
|
17
|
+
type redis = Redis::Connection | Redis::Pipeline
|
|
18
|
+
|
|
19
|
+
# A failure as a batch records it: "error_class" and "error_message".
|
|
20
|
+
type error_info = Hash[String, untyped]
|
|
21
|
+
|
|
22
|
+
# A callback: [target ("Class" or "Class#method"), options].
|
|
23
|
+
type callback = [String, Hash[String, untyped]]
|
|
24
|
+
|
|
25
|
+
EVENTS: Array[String]
|
|
26
|
+
TTL: Integer
|
|
27
|
+
CONTEXT: Symbol
|
|
28
|
+
RUNNING: Symbol
|
|
29
|
+
HOLD: Symbol
|
|
30
|
+
FAILURE: Symbol
|
|
31
|
+
|
|
32
|
+
# A batch job's failure as its ServerMiddleware saw it, held back while
|
|
33
|
+
# a processor runs the job.
|
|
34
|
+
class HeldFailure < Struct[untyped]
|
|
35
|
+
attr_accessor payload: job_hash
|
|
36
|
+
|
|
37
|
+
# nil until the job's middleware records its failure.
|
|
38
|
+
attr_accessor info: error_info?
|
|
39
|
+
|
|
40
|
+
def self.new: (job_hash payload, ?error_info? info) -> instance
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# What an atomic +jobs+ block holds back until it finishes.
|
|
44
|
+
class Hold < Struct[untyped]
|
|
45
|
+
# [batch, member] pairs to register.
|
|
46
|
+
attr_accessor members: Array[[Batch, member]]
|
|
47
|
+
|
|
48
|
+
# [client, payloads] pairs to push.
|
|
49
|
+
attr_accessor pushes: Array[Client::held]
|
|
50
|
+
|
|
51
|
+
# The batches the block created.
|
|
52
|
+
attr_accessor created: Array[Batch]
|
|
53
|
+
|
|
54
|
+
# The +jobs+ blocks inside it to close.
|
|
55
|
+
attr_accessor closes: Array[Batch]
|
|
56
|
+
|
|
57
|
+
def self.new: (Array[[Batch, member]] members, Array[Client::held] pushes, Array[Batch] created, Array[Batch] closes) -> instance
|
|
58
|
+
|
|
59
|
+
def self.empty: () -> Hold
|
|
60
|
+
|
|
61
|
+
# Registers the members, sends the jobs, then closes the inner blocks.
|
|
62
|
+
def release: () -> void
|
|
63
|
+
|
|
64
|
+
# Undoes the batches the block created and closes the inner blocks.
|
|
65
|
+
def discard: () -> void
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def by_batch: () -> Hash[Batch, Array[member]]
|
|
70
|
+
|
|
71
|
+
def shared_pool: () -> Redis::Pool?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
UPDATE: Redis::Script
|
|
75
|
+
CANCEL: Redis::Script
|
|
76
|
+
MARK_DEATH: Redis::Script
|
|
77
|
+
|
|
78
|
+
# The batch whose +jobs+ block is running in this thread.
|
|
79
|
+
def self.current: () -> Batch?
|
|
80
|
+
|
|
81
|
+
# The atomic +jobs+ block's hold, if one is running in this thread.
|
|
82
|
+
def self.hold: () -> Hold?
|
|
83
|
+
|
|
84
|
+
# Inside a +jobs+ block, holds back the members it registers and the
|
|
85
|
+
# jobs it pushes until it finishes. Returns the block's value.
|
|
86
|
+
def self.holding: [T] () { () -> T } -> T
|
|
87
|
+
|
|
88
|
+
# The batch hash, pending members set and failed members hash.
|
|
89
|
+
def self.tracking_keys: (Config config, String? bid) -> [String, String, String]
|
|
90
|
+
|
|
91
|
+
# The tracking keys and the children set.
|
|
92
|
+
def self.keys: (Config config, String? bid) -> Array[String]
|
|
93
|
+
|
|
94
|
+
# The index of batches tagged +tag+.
|
|
95
|
+
def self.tag_key: (Config config, String tag) -> String
|
|
96
|
+
|
|
97
|
+
def self.error_info: (Exception exception) -> error_info
|
|
98
|
+
|
|
99
|
+
# Newest batches first (only those tagged +tag+), as Status.summarize
|
|
100
|
+
# describes them.
|
|
101
|
+
def self.list: (?config: Config, ?limit: Integer, ?tag: String?) -> Array[Hash[String, untyped]]
|
|
102
|
+
|
|
103
|
+
def self.job_succeeded: (Config config, String bid, member member) -> void
|
|
104
|
+
|
|
105
|
+
def self.job_failed: (Config config, String bid, member member, error_info? info) -> void
|
|
106
|
+
|
|
107
|
+
# A batch job that raised.
|
|
108
|
+
def self.failed: (Config config, job_hash payload, error_info info) -> void
|
|
109
|
+
|
|
110
|
+
# Runs the block (a batch job) with its failure held back in +held+.
|
|
111
|
+
def self.holding_failure: [T] (HeldFailure held) { () -> T } -> T
|
|
112
|
+
|
|
113
|
+
# Queues a job's failure into +tx+.
|
|
114
|
+
def self.queue_failure: (redis tx, Config config, job_hash payload, error_info? info) -> void
|
|
115
|
+
|
|
116
|
+
# A job in a batch won't run again: records its failure and the batch's
|
|
117
|
+
# first death.
|
|
118
|
+
def self.job_died: (Config config, job_hash payload, Exception? exception) -> void
|
|
119
|
+
|
|
120
|
+
# Queues what #job_died records into +tx+.
|
|
121
|
+
def self.queue_death: (redis tx, Config config, job_hash payload, Exception? exception) -> void
|
|
122
|
+
|
|
123
|
+
# Runs the callbacks the replies to #queue_death call for.
|
|
124
|
+
def self.death_recorded: (Config config, String bid, Array[Redis::reply] replies) -> void
|
|
125
|
+
|
|
126
|
+
def self.died: (Config config, String bid) -> void
|
|
127
|
+
|
|
128
|
+
def self.eval_mark_death: (redis redis, Config config, String bid) -> Redis::reply
|
|
129
|
+
|
|
130
|
+
def self.death_marked: (Config config, String bid, Redis::reply reply) -> void
|
|
131
|
+
|
|
132
|
+
def self.update: (Config config, String bid, String mode, ?member? member, ?String? info) -> void
|
|
133
|
+
|
|
134
|
+
def self.eval_update: (redis redis, Config config, String bid, String mode, member? member, String? info) -> Redis::reply
|
|
135
|
+
|
|
136
|
+
# Runs the callbacks an UPDATE reply says just became due.
|
|
137
|
+
def self.updated: (Config config, String bid, Redis::reply reply) -> void
|
|
138
|
+
|
|
139
|
+
# Counts batch events, and times completed batches, in StatsD.
|
|
140
|
+
def self.report: (Config config, Array[String] events, String? created, String? tags) -> void
|
|
141
|
+
|
|
142
|
+
# Pushes the job running +bid+'s callbacks for +event+ (then +chain+'s).
|
|
143
|
+
def self.enqueue_callback: (Config config, String bid, String event, ?String? chain, queue: String?) -> String?
|
|
144
|
+
|
|
145
|
+
@callbacks: Hash[String, Array[callback]]
|
|
146
|
+
@cancelled: bool
|
|
147
|
+
@persisted: true?
|
|
148
|
+
@discarded: true?
|
|
149
|
+
|
|
150
|
+
attr_reader bid: String
|
|
151
|
+
attr_reader config: Config
|
|
152
|
+
attr_reader parent_bid: String?
|
|
153
|
+
attr_reader tags: Array[String]
|
|
154
|
+
|
|
155
|
+
attr_accessor description: String?
|
|
156
|
+
|
|
157
|
+
# The queue the callbacks' job runs on (nil: the default).
|
|
158
|
+
attr_accessor callback_queue: String?
|
|
159
|
+
|
|
160
|
+
# A new batch, or (with +bid+) an existing one; raises NoSuchBatch for
|
|
161
|
+
# one that doesn't exist.
|
|
162
|
+
def initialize: (?String? bid, ?config: Config) -> void
|
|
163
|
+
|
|
164
|
+
# Registers a callback for :complete, :success or :death: a class
|
|
165
|
+
# (whose on_<event> is called) or "Class#method".
|
|
166
|
+
def on: (Symbol | String event, Class | String target, ?Hash[String | Symbol, untyped] options) -> self
|
|
167
|
+
|
|
168
|
+
def callbacks: () -> Hash[String, Array[callback]]
|
|
169
|
+
|
|
170
|
+
# Labels for finding the batch later; set before the first +jobs+.
|
|
171
|
+
def tags=: (_ToS | Array[_ToS] list) -> void
|
|
172
|
+
|
|
173
|
+
# Runs the block; every job pushed inside it belongs to this batch.
|
|
174
|
+
# Returns the bid.
|
|
175
|
+
def jobs: (?atomic: bool) { () -> void } -> String
|
|
176
|
+
|
|
177
|
+
# Ends one +jobs+ block.
|
|
178
|
+
def close: () -> void
|
|
179
|
+
|
|
180
|
+
def status: () -> Status
|
|
181
|
+
|
|
182
|
+
# Cancels this batch and its child batches; returns the bids cancelled.
|
|
183
|
+
def cancel!: () -> Array[String]
|
|
184
|
+
|
|
185
|
+
def cancelled?: () -> bool
|
|
186
|
+
|
|
187
|
+
def parent: () -> Batch?
|
|
188
|
+
|
|
189
|
+
# Adds +member+ to the pending set.
|
|
190
|
+
def register: (member member) -> void
|
|
191
|
+
|
|
192
|
+
def register_all: (Array[member] members) -> void
|
|
193
|
+
|
|
194
|
+
# Queues the commands registering +members+ into +tx+.
|
|
195
|
+
def queue_register: (redis tx, Array[member] members) -> void
|
|
196
|
+
|
|
197
|
+
# Deletes a batch an atomic +jobs+ block created before it raised.
|
|
198
|
+
def discard!: () -> true
|
|
199
|
+
|
|
200
|
+
private
|
|
201
|
+
|
|
202
|
+
def parent_for_new: () -> String?
|
|
203
|
+
|
|
204
|
+
def persist!: () -> void
|
|
205
|
+
|
|
206
|
+
# Read-only view of a batch, handed to callbacks and the web UI.
|
|
207
|
+
class Status
|
|
208
|
+
INTS: Array[String]
|
|
209
|
+
|
|
210
|
+
# A batch's hash as JSON-ready fields.
|
|
211
|
+
def self.summarize: (String bid, Hash[String, String] data) -> Hash[String, untyped]
|
|
212
|
+
|
|
213
|
+
@config: Config
|
|
214
|
+
@data: Hash[String, String]
|
|
215
|
+
|
|
216
|
+
attr_reader bid: String
|
|
217
|
+
|
|
218
|
+
def initialize: (String bid, ?config: Config) -> void
|
|
219
|
+
|
|
220
|
+
def exists?: () -> bool
|
|
221
|
+
|
|
222
|
+
def total: () -> Integer
|
|
223
|
+
|
|
224
|
+
def pending: () -> Integer
|
|
225
|
+
|
|
226
|
+
def failures: () -> Integer
|
|
227
|
+
|
|
228
|
+
def description: () -> String?
|
|
229
|
+
|
|
230
|
+
def parent_bid: () -> String?
|
|
231
|
+
|
|
232
|
+
def callback_queue: () -> String?
|
|
233
|
+
|
|
234
|
+
def tags: () -> Array[String]
|
|
235
|
+
|
|
236
|
+
def created_at: () -> Integer?
|
|
237
|
+
|
|
238
|
+
def complete?: () -> bool
|
|
239
|
+
|
|
240
|
+
def success?: () -> bool
|
|
241
|
+
|
|
242
|
+
def dead?: () -> bool
|
|
243
|
+
|
|
244
|
+
def cancelled?: () -> bool
|
|
245
|
+
|
|
246
|
+
def callbacks: () -> Hash[String, Array[callback]]
|
|
247
|
+
|
|
248
|
+
def jids: () -> Array[String]
|
|
249
|
+
|
|
250
|
+
def children: () -> Array[String]
|
|
251
|
+
|
|
252
|
+
# {"jid", "error_class", "error_message"} each.
|
|
253
|
+
def failed_jobs: () -> Array[Hash[String, untyped]]
|
|
254
|
+
|
|
255
|
+
# Counts and states only.
|
|
256
|
+
def progress: () -> Hash[String, String | Integer | bool]
|
|
257
|
+
|
|
258
|
+
def to_h: () -> Hash[String, untyped]
|
|
259
|
+
|
|
260
|
+
def delete!: () -> true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Runs a batch's callbacks for one event, then propagates the outcome to
|
|
264
|
+
# the parent batch.
|
|
265
|
+
class Callback
|
|
266
|
+
include Job
|
|
267
|
+
extend Job::ClassMethods
|
|
268
|
+
|
|
269
|
+
def perform: (String bid, String event, ?String? chain) -> void
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Tags jobs pushed inside a +jobs+ block with the batch id.
|
|
273
|
+
class ClientMiddleware
|
|
274
|
+
include Middleware::ConfigAware
|
|
275
|
+
include Middleware::Stateless
|
|
276
|
+
|
|
277
|
+
def self.applies?: (*untyped) -> bool
|
|
278
|
+
|
|
279
|
+
def call: (String job_class, job_hash payload, String queue, Redis::Pool redis) { () -> job_hash? } -> job_hash?
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# Records the outcome of batch jobs.
|
|
283
|
+
class ServerMiddleware
|
|
284
|
+
include Middleware::ConfigAware
|
|
285
|
+
include Middleware::Stateless
|
|
286
|
+
|
|
287
|
+
def self.applies?: (untyped job, job_hash payload, String queue) -> bool
|
|
288
|
+
|
|
289
|
+
def call: (untyped job, job_hash payload, String queue) { () -> untyped } -> untyped
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Cooperative job cancellation (see Robin.cancel!).
|
|
3
|
+
module Cancellation
|
|
4
|
+
# Each config's local copy of the cancellation list, by its object_id.
|
|
5
|
+
self.@cache: Hash[Integer, Set[String]]
|
|
6
|
+
|
|
7
|
+
# Cancels jobs (jids, or "batch:<bid>" for a batch's) for +ttl+
|
|
8
|
+
# seconds.
|
|
9
|
+
def self.cancel!: (*String | Array[String] jids, ?ttl: Integer, ?config: Config) -> true
|
|
10
|
+
|
|
11
|
+
# Live check against Redis: was the job, or its batch, cancelled?
|
|
12
|
+
def self.cancelled?: (String? jid, ?bid: String?, ?config: Config) -> bool
|
|
13
|
+
|
|
14
|
+
# Fast in-memory check used by processors.
|
|
15
|
+
def self.skip?: (Config config, String jid, ?String? bid) -> bool
|
|
16
|
+
|
|
17
|
+
def self.refresh: (Config config, Redis::Connection conn) -> Set[String]
|
|
18
|
+
|
|
19
|
+
# The command that reads the live cancellation list.
|
|
20
|
+
def self.listing: (Config config) -> Redis::command
|
|
21
|
+
|
|
22
|
+
# Replaces the local copy of the cancellation list.
|
|
23
|
+
def self.store: (Config config, Array[String] jids) -> Set[String]
|
|
24
|
+
end
|
|
25
|
+
end
|
data/sig/robin/cli.rbs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# The `robin` command.
|
|
3
|
+
class CLI
|
|
4
|
+
# CLI.app_loaders: loads the application in a directory; truthy when it
|
|
5
|
+
# did.
|
|
6
|
+
interface _AppLoader
|
|
7
|
+
def call: (String dir) -> boolish
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# CLI.config_file_hooks: applies settings of the config file's (Symbol
|
|
11
|
+
# keys, the environment's section merged in) to the config.
|
|
12
|
+
interface _ConfigFileHook
|
|
13
|
+
def call: (Hash[Symbol, untyped] settings, Config config) -> void
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
SIGNALS: Array[String]
|
|
17
|
+
|
|
18
|
+
PLUGIN_GLOB: String
|
|
19
|
+
|
|
20
|
+
HEALTH_TIMEOUT: Integer
|
|
21
|
+
|
|
22
|
+
self.@app_loaders: Array[_AppLoader]
|
|
23
|
+
self.@environment_variables: Array[String]
|
|
24
|
+
self.@config_paths: Array[String]
|
|
25
|
+
self.@config_file_hooks: Array[_ConfigFileHook]
|
|
26
|
+
|
|
27
|
+
def self.app_loaders: () -> Array[_AppLoader]
|
|
28
|
+
|
|
29
|
+
def self.environment_variables: () -> Array[String]
|
|
30
|
+
|
|
31
|
+
def self.config_paths: () -> Array[String]
|
|
32
|
+
|
|
33
|
+
def self.config_file_hooks: () -> Array[_ConfigFileHook]
|
|
34
|
+
|
|
35
|
+
# The app directory's name (or a Capistrano-style release's app's).
|
|
36
|
+
def self.default_tag: (String dir) -> String
|
|
37
|
+
|
|
38
|
+
def self.plugin_files: () -> Array[String]
|
|
39
|
+
|
|
40
|
+
def self.load_plugins: () -> void
|
|
41
|
+
|
|
42
|
+
@argv: Array[String]
|
|
43
|
+
# Options from the command line and the config file (Symbol keys).
|
|
44
|
+
@options: Hash[Symbol, untyped]
|
|
45
|
+
@file_options: Hash[Symbol, untyped]
|
|
46
|
+
# nil until #serve.
|
|
47
|
+
@launcher: Launcher
|
|
48
|
+
# nil until #serve.
|
|
49
|
+
@signals: IO
|
|
50
|
+
|
|
51
|
+
attr_reader config: Config
|
|
52
|
+
|
|
53
|
+
# The server's launcher, once #serve runs.
|
|
54
|
+
def launcher: () -> Launcher?
|
|
55
|
+
|
|
56
|
+
def initialize: (?Array[String] argv, ?config: Config) -> void
|
|
57
|
+
|
|
58
|
+
def run: () -> void
|
|
59
|
+
|
|
60
|
+
def parse: () -> Hash[Symbol, untyped]
|
|
61
|
+
|
|
62
|
+
# Options from the command line and the config file.
|
|
63
|
+
attr_reader options: Hash[Symbol, untyped]
|
|
64
|
+
|
|
65
|
+
# Loads the application and applies options.
|
|
66
|
+
def boot: (?server: bool) -> void
|
|
67
|
+
|
|
68
|
+
def prepare: () -> void
|
|
69
|
+
|
|
70
|
+
# Runs a server until INT or TERM.
|
|
71
|
+
def serve: () -> void
|
|
72
|
+
|
|
73
|
+
# Hands a signal to the serving thread.
|
|
74
|
+
def signal: (String name) -> void
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def build_launcher: () -> Launcher
|
|
79
|
+
|
|
80
|
+
def trap_signals: (Array[String] names) -> Hash[String, Signal::trap_command]
|
|
81
|
+
|
|
82
|
+
def chain: (untyped handler, Integer signo) -> void
|
|
83
|
+
|
|
84
|
+
def wait_for_signals: (IO reader) -> void
|
|
85
|
+
|
|
86
|
+
def reopen_logs: () -> void
|
|
87
|
+
|
|
88
|
+
def health_check: () -> bool
|
|
89
|
+
|
|
90
|
+
def health_http: (Integer | String port) -> Net::HTTP
|
|
91
|
+
|
|
92
|
+
def load_config_file: () -> void
|
|
93
|
+
|
|
94
|
+
def apply_options: () -> void
|
|
95
|
+
|
|
96
|
+
def load_application: () -> void
|
|
97
|
+
|
|
98
|
+
def load_directory: (String path) -> void
|
|
99
|
+
|
|
100
|
+
def print_banner: () -> void
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Pushes jobs into Redis.
|
|
3
|
+
class Client
|
|
4
|
+
class ArgumentError < ::ArgumentError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# Client.interceptor: may take over delivery (Robin::Testing keeps jobs
|
|
8
|
+
# in memory); truthy when it handled the push.
|
|
9
|
+
interface _Interceptor
|
|
10
|
+
def call: (Array[job_hash] payloads) -> boolish
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# A lambda or another callable (Steep doesn't count a proc as an Object,
|
|
14
|
+
# so a lambda isn't an `Object & _Interceptor`).
|
|
15
|
+
type interceptor = ^(Array[job_hash] payloads) -> boolish | (Object & _Interceptor)
|
|
16
|
+
|
|
17
|
+
# A Client.rewriters entry: returns the job hash to push.
|
|
18
|
+
interface _Rewriter
|
|
19
|
+
def call: (job_hash item) -> job_hash
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# What a Client.together block holds: the client and its payloads.
|
|
23
|
+
type held = [Client, Array[job_hash]]
|
|
24
|
+
|
|
25
|
+
self.@interceptor: interceptor?
|
|
26
|
+
self.@rewriters: Array[_Rewriter]?
|
|
27
|
+
|
|
28
|
+
def self.interceptor: () -> interceptor?
|
|
29
|
+
|
|
30
|
+
def self.interceptor=: (interceptor? interceptor) -> interceptor?
|
|
31
|
+
|
|
32
|
+
# Callables that may rewrite a job hash before #push handles it.
|
|
33
|
+
def self.rewriters: () -> Array[_Rewriter]
|
|
34
|
+
|
|
35
|
+
# Sends every push this thread makes inside the block to +pool+.
|
|
36
|
+
def self.via: [T] (Redis::Pool? pool) { () -> T } -> T
|
|
37
|
+
|
|
38
|
+
# The pool set by an enclosing Client.via block, if any.
|
|
39
|
+
def self.current_pool: () -> Redis::Pool?
|
|
40
|
+
|
|
41
|
+
# Holds back this thread's pushes inside the block and sends them all
|
|
42
|
+
# when it finishes. Returns the block's value.
|
|
43
|
+
def self.together: [T] () { () -> T } -> T
|
|
44
|
+
|
|
45
|
+
private def self.send_together: (Array[held] held) -> void
|
|
46
|
+
|
|
47
|
+
def self.push: (Hash[String | Symbol, untyped] item) -> String?
|
|
48
|
+
|
|
49
|
+
def self.push_bulk: (Hash[String | Symbol, untyped] items) -> Array[String?]
|
|
50
|
+
|
|
51
|
+
# Converts a delay (seconds), a Time, or an epoch timestamp (seconds or
|
|
52
|
+
# milliseconds) to epoch milliseconds: a +time+, though it takes anything
|
|
53
|
+
# with #to_time or #to_f (and raises for nil).
|
|
54
|
+
def self.timestamp_ms: (untyped value, ?Integer now) -> Integer
|
|
55
|
+
|
|
56
|
+
# +count+ times spread evenly over +interval+ seconds, from +start+, as
|
|
57
|
+
# epoch milliseconds.
|
|
58
|
+
def self.spread: (Integer count, untyped interval, ?time start) -> Array[Integer]
|
|
59
|
+
|
|
60
|
+
@config: Config
|
|
61
|
+
@pool: Redis::Pool?
|
|
62
|
+
@chain: Middleware::Chain?
|
|
63
|
+
|
|
64
|
+
attr_reader config: Config
|
|
65
|
+
|
|
66
|
+
def initialize: (?config: Config, ?pool: Redis::Pool?, ?chain: Middleware::Chain?) -> void
|
|
67
|
+
|
|
68
|
+
def middleware: () -> Middleware::Chain
|
|
69
|
+
|
|
70
|
+
def redis_pool: () -> Redis::Pool
|
|
71
|
+
|
|
72
|
+
# Pushes a single job. Returns its jid, or nil if a client middleware
|
|
73
|
+
# stopped the push.
|
|
74
|
+
def push: (Hash[String | Symbol, untyped] item) -> String?
|
|
75
|
+
|
|
76
|
+
# Pushes many jobs of the same class at once ("args": an Array of
|
|
77
|
+
# argument Arrays). Returns the jids (nil for any job middleware stopped).
|
|
78
|
+
def push_bulk: (Hash[String | Symbol, untyped] item) -> Array[String?]
|
|
79
|
+
|
|
80
|
+
# Fills in defaults and validates a job hash.
|
|
81
|
+
def normalize: (Hash[String | Symbol, untyped] item) -> job_hash
|
|
82
|
+
|
|
83
|
+
# Would #deliver_now send these jobs to Redis right away?
|
|
84
|
+
def direct?: (Array[job_hash] payloads) -> bool
|
|
85
|
+
|
|
86
|
+
# Does #send_payloads go straight to Redis?
|
|
87
|
+
def plain?: () -> bool
|
|
88
|
+
|
|
89
|
+
# Delivers now, without waiting for an atomic batch block.
|
|
90
|
+
def deliver_now: (Array[job_hash] payloads) -> void
|
|
91
|
+
|
|
92
|
+
# Queues the commands pushing +payloads+ into +pipe+.
|
|
93
|
+
def queue_push: (Redis::Pipeline pipe, Array[job_hash] payloads) -> void
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def build: (job_hash template, Array[untyped] args, String? jid, time? at) -> job_hash
|
|
98
|
+
|
|
99
|
+
def run_middleware: (job_hash payload) -> job_hash?
|
|
100
|
+
|
|
101
|
+
def invoke_middleware: (job_hash payload) -> job_hash?
|
|
102
|
+
|
|
103
|
+
def schedule: (job_hash payload, Integer at_ms) -> void
|
|
104
|
+
|
|
105
|
+
def deliver: (Array[job_hash] payloads) -> void
|
|
106
|
+
|
|
107
|
+
def send_payloads: (Array[job_hash] payloads) -> void
|
|
108
|
+
|
|
109
|
+
def raw_push: (Array[job_hash] payloads) -> void
|
|
110
|
+
|
|
111
|
+
def index_jids: (Redis::Pipeline pipe, Array[job_hash] payloads) -> void
|
|
112
|
+
|
|
113
|
+
def check_args: (job_hash item) -> void
|
|
114
|
+
|
|
115
|
+
# The first value (or hash key) that doesn't survive a JSON round trip.
|
|
116
|
+
def find_non_native: (untyped obj) -> untyped
|
|
117
|
+
end
|
|
118
|
+
end
|