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/swarm.rbs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Runs several Robin processes on one machine from a single command
|
|
3
|
+
# (`robin swarm`).
|
|
4
|
+
class Swarm
|
|
5
|
+
READY_TIMEOUT: Integer
|
|
6
|
+
|
|
7
|
+
MIN_UPTIME: Integer
|
|
8
|
+
|
|
9
|
+
MAX_DELAY: Integer
|
|
10
|
+
|
|
11
|
+
SIGNALS: Array[String]
|
|
12
|
+
|
|
13
|
+
EXE: String
|
|
14
|
+
|
|
15
|
+
LIB: String
|
|
16
|
+
|
|
17
|
+
# A child process: its pid, index (0...n), when it started (monotonic
|
|
18
|
+
# seconds), and whether it's being replaced.
|
|
19
|
+
class Child < Struct[Integer | Float | bool]
|
|
20
|
+
attr_accessor pid: Integer
|
|
21
|
+
attr_accessor index: Integer
|
|
22
|
+
attr_accessor started_at: Float
|
|
23
|
+
attr_accessor retiring: bool
|
|
24
|
+
|
|
25
|
+
def self.new: (Integer pid, Integer index, Float started_at, bool retiring) -> instance
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Operating-system primitives, separated so the supervisor logic can be
|
|
29
|
+
# tested without real processes.
|
|
30
|
+
class OS
|
|
31
|
+
SIGNAL_BUFFER: Integer
|
|
32
|
+
|
|
33
|
+
def fork?: () -> bool
|
|
34
|
+
|
|
35
|
+
def fork: () { () -> void } -> Integer
|
|
36
|
+
|
|
37
|
+
def spawn: (Hash[String, String] env, *String command) -> Integer
|
|
38
|
+
|
|
39
|
+
# Tidies the heap so forked children share more memory.
|
|
40
|
+
def warmup: () -> void
|
|
41
|
+
|
|
42
|
+
def kill: (Integer pid, String | Integer signal) -> Integer?
|
|
43
|
+
|
|
44
|
+
# [pid, status] of an exited child, or nil.
|
|
45
|
+
def wait: (?block: bool) -> [Integer, Process::Status]?
|
|
46
|
+
|
|
47
|
+
def now: () -> Float
|
|
48
|
+
|
|
49
|
+
def sleep: (seconds seconds) -> Integer
|
|
50
|
+
|
|
51
|
+
# Routes +signals+ into a pipe; returns its reading end.
|
|
52
|
+
def trap_signals: (Array[String] signals) -> IO
|
|
53
|
+
|
|
54
|
+
def reset_signals: (Array[String] signals) -> void
|
|
55
|
+
|
|
56
|
+
# Signals received within +timeout+ seconds.
|
|
57
|
+
def read_signals: (IO reader, seconds timeout) -> Array[String]
|
|
58
|
+
|
|
59
|
+
def finish_child: () -> bot
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def wait2: (bool block) -> [Integer, Process::Status]?
|
|
64
|
+
|
|
65
|
+
def notify: (IO writer, String signal) -> void
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Stops this process when +parent+ goes away.
|
|
69
|
+
def self.watch_parent: (Integer parent, ?os: OS, ?interval: seconds) -> Thread
|
|
70
|
+
|
|
71
|
+
# Children for a count setting: a whole number, or a decimal per core.
|
|
72
|
+
def self.process_count: (String | Integer | Float | nil value, ?Integer cores) -> Integer
|
|
73
|
+
|
|
74
|
+
# Watches the swarm parent named in ROBIN_SWARM_PARENT, if it is ours.
|
|
75
|
+
def self.watch_parent_from_env: (?_Env env, ?os: OS) -> Thread?
|
|
76
|
+
|
|
77
|
+
@cli: CLI
|
|
78
|
+
@config: Config
|
|
79
|
+
@os: OS
|
|
80
|
+
@crashes: Hash[Integer, Integer]
|
|
81
|
+
@restarts: Hash[Integer, Float]
|
|
82
|
+
# nil until #run.
|
|
83
|
+
@signals: IO
|
|
84
|
+
@stopping: bool?
|
|
85
|
+
|
|
86
|
+
# Running children by pid.
|
|
87
|
+
attr_reader children: Hash[Integer, Child]
|
|
88
|
+
|
|
89
|
+
attr_reader count: Integer
|
|
90
|
+
|
|
91
|
+
# "fork" or "spawn".
|
|
92
|
+
attr_reader mode: String
|
|
93
|
+
|
|
94
|
+
def initialize: (CLI cli, ?os: OS) -> void
|
|
95
|
+
|
|
96
|
+
def run: () -> void
|
|
97
|
+
|
|
98
|
+
def handle: (String signal) -> void
|
|
99
|
+
|
|
100
|
+
def shutdown: () -> void
|
|
101
|
+
|
|
102
|
+
def rolling_restart: () -> void
|
|
103
|
+
|
|
104
|
+
# The options a spawned child needs to run like this process.
|
|
105
|
+
def child_arguments: () -> Array[String]
|
|
106
|
+
|
|
107
|
+
def child_command: () -> Array[String]
|
|
108
|
+
|
|
109
|
+
def child_env: (Integer index) -> Hash[String, String]
|
|
110
|
+
|
|
111
|
+
def start_child: (Integer index) -> Child
|
|
112
|
+
|
|
113
|
+
# Runs inside a forked child.
|
|
114
|
+
def child_main: (Integer index) -> bot
|
|
115
|
+
|
|
116
|
+
# Collects exited children and schedules replacements.
|
|
117
|
+
def reap: (?block: bool) -> void
|
|
118
|
+
|
|
119
|
+
def start_due_restarts: () -> void
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
def logger: () -> Logger
|
|
124
|
+
|
|
125
|
+
def ready?: (Child child) -> bool
|
|
126
|
+
|
|
127
|
+
def stop_child: (Child child) -> void
|
|
128
|
+
|
|
129
|
+
def wait_for: (?seconds seconds, ?poll: seconds) { () -> boolish } -> bool
|
|
130
|
+
|
|
131
|
+
def signal_children: (String signal) -> void
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Tells systemd how the server is doing (Type=notify services).
|
|
3
|
+
module Systemd
|
|
4
|
+
# Sends +state+ (e.g. "READY=1"). True if it was sent.
|
|
5
|
+
def self.notify: (String state, ?env: _Env) -> bool
|
|
6
|
+
|
|
7
|
+
# A leading "@" means Linux's abstract socket namespace.
|
|
8
|
+
def self.address: (String path) -> String
|
|
9
|
+
|
|
10
|
+
# Whether systemd watches this process.
|
|
11
|
+
def self.watchdog?: (?env: _Env, ?pid: Integer) -> bool
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Test helpers (require "robin/testing"): pushes are kept in memory
|
|
3
|
+
# (fake mode), run right away (inline mode), or go to Redis (disabled).
|
|
4
|
+
module Testing
|
|
5
|
+
type mode = :fake | :inline | :disable
|
|
6
|
+
|
|
7
|
+
class EmptyQueue < Robin::Error
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
self.@mode: mode
|
|
11
|
+
self.@queues: Hash[String, Array[job_hash]]
|
|
12
|
+
self.@mutex: Monitor
|
|
13
|
+
|
|
14
|
+
MODE_KEY: Symbol
|
|
15
|
+
|
|
16
|
+
# The current thread's mode.
|
|
17
|
+
def self.mode: () -> mode
|
|
18
|
+
|
|
19
|
+
# Switches to a mode: for the block on this thread (returning its
|
|
20
|
+
# value), or without one as every thread's default.
|
|
21
|
+
def self.fake!: [T] () ?{ () -> T } -> T?
|
|
22
|
+
|
|
23
|
+
def self.inline!: [T] () ?{ () -> T } -> T?
|
|
24
|
+
|
|
25
|
+
def self.disable!: [T] () ?{ () -> T } -> T?
|
|
26
|
+
|
|
27
|
+
def self.fake?: () -> bool
|
|
28
|
+
|
|
29
|
+
def self.inline?: () -> bool
|
|
30
|
+
|
|
31
|
+
def self.disabled?: () -> bool
|
|
32
|
+
|
|
33
|
+
# Every faked job, in push order, keyed by queue.
|
|
34
|
+
def self.queues: () -> Hash[String, Array[job_hash]]
|
|
35
|
+
|
|
36
|
+
# Every faked job across all queues.
|
|
37
|
+
def self.jobs: () -> Array[job_hash]
|
|
38
|
+
|
|
39
|
+
def self.jobs_for: (String? class_name) -> Array[job_hash]
|
|
40
|
+
|
|
41
|
+
def self.clear_all: () -> void
|
|
42
|
+
|
|
43
|
+
def self.clear: (String? class_name) -> void
|
|
44
|
+
|
|
45
|
+
# Runs faked jobs (including any they push) until none are left.
|
|
46
|
+
def self.drain_all: () -> void
|
|
47
|
+
|
|
48
|
+
# Runs faked jobs of one class until none are left.
|
|
49
|
+
def self.drain: (String? class_name) -> void
|
|
50
|
+
|
|
51
|
+
# Runs the next faked job of the class; returns what its #perform
|
|
52
|
+
# returns.
|
|
53
|
+
def self.perform_one: (String? class_name) -> untyped
|
|
54
|
+
|
|
55
|
+
# Called by the client in place of a Redis push.
|
|
56
|
+
def self.push: (Array[job_hash] payloads) -> Array[job_hash]
|
|
57
|
+
|
|
58
|
+
# Runs one job hash through the server middleware chain; returns what
|
|
59
|
+
# the job's #perform returns.
|
|
60
|
+
def self.execute: (job_hash payload, ?config: Config) -> untyped
|
|
61
|
+
|
|
62
|
+
private def self.switch: [T] (mode mode) ?{ () -> T } -> T?
|
|
63
|
+
|
|
64
|
+
private def self.shift_next: (?String? class_name) -> job_hash?
|
|
65
|
+
|
|
66
|
+
# Routes pushes to memory unless testing is disabled.
|
|
67
|
+
def self.intercept: (Array[job_hash] payloads) -> Array[job_hash]?
|
|
68
|
+
|
|
69
|
+
# Class-level helpers on every Robin::Job class.
|
|
70
|
+
module JobMethods : Job::_JobClass
|
|
71
|
+
def jobs: () -> Array[job_hash]
|
|
72
|
+
|
|
73
|
+
def clear: () -> void
|
|
74
|
+
|
|
75
|
+
def drain: () -> void
|
|
76
|
+
|
|
77
|
+
def perform_one: () -> untyped
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/sig/robin/top.rbs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# A live view of a cluster in the terminal: `robin top`.
|
|
3
|
+
class Top
|
|
4
|
+
VIEWS: Array[String]
|
|
5
|
+
|
|
6
|
+
QUIT: Array[String]
|
|
7
|
+
|
|
8
|
+
DEFAULT_SIZE: [Integer, Integer]
|
|
9
|
+
|
|
10
|
+
KEY_BUFFER: Integer
|
|
11
|
+
|
|
12
|
+
# A queue's row: name, size, latency (seconds), whether it's paused.
|
|
13
|
+
type queue_row = [String, Integer, Float, bool]
|
|
14
|
+
|
|
15
|
+
# Everything one frame shows, read from Redis in one go.
|
|
16
|
+
class Snapshot < Struct[untyped]
|
|
17
|
+
attr_accessor stats: Stats
|
|
18
|
+
attr_accessor queues: Array[queue_row]
|
|
19
|
+
attr_accessor processes: Array[ProcessRecord]
|
|
20
|
+
attr_accessor work: Array[[String, String, Hash[String, untyped]]]
|
|
21
|
+
attr_accessor at: Integer
|
|
22
|
+
|
|
23
|
+
def self.new: (Stats stats, Array[queue_row] queues, Array[ProcessRecord] processes, Array[[String, String, Hash[String, untyped]]] work, Integer at) -> instance
|
|
24
|
+
|
|
25
|
+
def self.take: (Config config) -> Snapshot
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
@config: Config
|
|
29
|
+
@input: IO
|
|
30
|
+
@output: IO
|
|
31
|
+
@interval: seconds
|
|
32
|
+
|
|
33
|
+
# The view shown: 0 (overview), 1 (processes) or 2 (busy).
|
|
34
|
+
attr_reader view: Integer
|
|
35
|
+
|
|
36
|
+
def initialize: (?config: Config, ?input: IO, ?output: IO, ?interval: seconds) -> void
|
|
37
|
+
|
|
38
|
+
# Runs until a quit key (or the end of input).
|
|
39
|
+
def run: () -> void
|
|
40
|
+
|
|
41
|
+
# One frame for a terminal +height+ lines by +width+ columns.
|
|
42
|
+
def frame: (Integer height, Integer width) -> Array[String]
|
|
43
|
+
|
|
44
|
+
# Acts on a key press; false means quit.
|
|
45
|
+
def key: (String char) -> bool
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def loop_frames: () -> void
|
|
50
|
+
|
|
51
|
+
def size: () -> [Integer, Integer]
|
|
52
|
+
|
|
53
|
+
def header: (Integer width) -> String
|
|
54
|
+
|
|
55
|
+
def tabs: () -> String
|
|
56
|
+
|
|
57
|
+
def body: (Snapshot snap) -> Array[String]
|
|
58
|
+
|
|
59
|
+
def overview: (Snapshot snap) -> Array[String]
|
|
60
|
+
|
|
61
|
+
def processes: (Snapshot snap) -> Array[String]
|
|
62
|
+
|
|
63
|
+
def busy: (Snapshot snap) -> Array[String]
|
|
64
|
+
|
|
65
|
+
def table: (Array[String] headers, Array[Array[String]] rows, right: Array[Integer], empty: String) -> Array[String]
|
|
66
|
+
|
|
67
|
+
def pairs: (Hash[String, String] hash) -> String
|
|
68
|
+
|
|
69
|
+
def fit: (String line, Integer width) -> String
|
|
70
|
+
|
|
71
|
+
def number: (_ToI? n) -> String
|
|
72
|
+
|
|
73
|
+
def megabytes: (Integer kb) -> String
|
|
74
|
+
|
|
75
|
+
def since: (Integer now, Integer? ms) -> String
|
|
76
|
+
|
|
77
|
+
def duration: (_ToF? seconds) -> String
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Unique jobs: suppress pushes of a job identical (same class, queue and
|
|
3
|
+
# arguments) to one that's still pending (robin_options unique_for:).
|
|
4
|
+
module Unique
|
|
5
|
+
# A lock for a job: [digest, lock key, won?].
|
|
6
|
+
type claim = [String, String, boolish]
|
|
7
|
+
|
|
8
|
+
# Where a lock is released: a connection (which replies), or a
|
|
9
|
+
# pipeline or transaction to queue it in.
|
|
10
|
+
type redis = Redis::Connection | Redis::Pipeline
|
|
11
|
+
|
|
12
|
+
CLAIMS: Symbol
|
|
13
|
+
|
|
14
|
+
# The lock digest of a job's class name, queue and (unique) arguments.
|
|
15
|
+
def self.digest: (String klass_name, String queue, Array[untyped] args) -> String
|
|
16
|
+
|
|
17
|
+
# Hashes become key-sorted pairs (string keys).
|
|
18
|
+
def self.canonical: (untyped obj) -> untyped
|
|
19
|
+
|
|
20
|
+
def self.lock_key: (Config config, String digest) -> String
|
|
21
|
+
|
|
22
|
+
# Does a job take a lock when it's pushed?
|
|
23
|
+
def self.lockable?: (job_hash payload) -> boolish
|
|
24
|
+
|
|
25
|
+
# Runs the block (a bulk push of +payloads+) with their unique locks
|
|
26
|
+
# taken beforehand, when +chain+ starts with ClientMiddleware.
|
|
27
|
+
def self.claiming: [T] (Middleware::Chain chain, Array[job_hash] payloads) { () -> T } -> T
|
|
28
|
+
|
|
29
|
+
# Is a lock currently held for these arguments?
|
|
30
|
+
def self.locked?: (String klass_name, Array[untyped] args, ?queue: String, ?config: Config) -> bool
|
|
31
|
+
|
|
32
|
+
def self.release: (Config config, job_hash payload) -> Redis::reply
|
|
33
|
+
|
|
34
|
+
# Releases +payload+'s lock, if it has one and still holds it.
|
|
35
|
+
def self.eval_release: (redis redis, Config config, job_hash payload) -> Redis::reply
|
|
36
|
+
|
|
37
|
+
private def self.compare_and_delete: (redis redis, String key, String owner) -> Redis::reply
|
|
38
|
+
|
|
39
|
+
private def self.constant: (String name) -> untyped
|
|
40
|
+
|
|
41
|
+
class ClientMiddleware
|
|
42
|
+
include Middleware::ConfigAware
|
|
43
|
+
include Middleware::Stateless
|
|
44
|
+
|
|
45
|
+
def self.applies?: (String job_class, job_hash payload, String queue, Redis::Pool redis) -> boolish
|
|
46
|
+
|
|
47
|
+
def call: (String job_class, job_hash payload, String queue, Redis::Pool redis) { () -> job_hash? } -> job_hash?
|
|
48
|
+
|
|
49
|
+
# Takes the locks of +payloads+ in one round trip; returns {payload
|
|
50
|
+
# => claim}, by identity.
|
|
51
|
+
def claim_all: (Array[job_hash] payloads) -> Hash[job_hash, claim]
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def claim: (String job_class, job_hash payload, String queue) -> claim
|
|
56
|
+
|
|
57
|
+
# [digest, lock key, expiry (epoch ms)] for a job.
|
|
58
|
+
def lock_for: (String job_class, job_hash payload, String queue) -> [String, String, Integer]
|
|
59
|
+
|
|
60
|
+
def set_command: (job_hash payload, String key, Integer expires_at) -> Redis::command
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class ServerMiddleware
|
|
64
|
+
include Middleware::ConfigAware
|
|
65
|
+
include Middleware::Stateless
|
|
66
|
+
|
|
67
|
+
def self.applies?: (untyped job, job_hash payload, String queue) -> bool
|
|
68
|
+
|
|
69
|
+
def call: (untyped job, job_hash payload, String queue) { () -> untyped } -> untyped
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
# Warms up the JIT before a server starts (see Config#jit_warmup).
|
|
3
|
+
module Warmup
|
|
4
|
+
ROUNDS: Integer
|
|
5
|
+
|
|
6
|
+
JOBS: Integer
|
|
7
|
+
|
|
8
|
+
ARGS: Array[untyped]
|
|
9
|
+
|
|
10
|
+
# A connection that never connects: it encodes each round trip's
|
|
11
|
+
# commands and answers every one with +reply+.
|
|
12
|
+
class Connection < Redis::Connection
|
|
13
|
+
@reply: String
|
|
14
|
+
|
|
15
|
+
def initialize: (String reply) -> void
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def roundtrip: (Array[Redis::command] commands, seconds _read_timeout) -> Array[Redis::reply]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# A pool of the one connection, for client middleware.
|
|
23
|
+
class Pool < Struct[Connection]
|
|
24
|
+
attr_accessor connection: Connection
|
|
25
|
+
|
|
26
|
+
def self.new: (Connection connection) -> instance
|
|
27
|
+
|
|
28
|
+
def with: [T] () { (Connection conn) -> T } -> T
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.run: (Config config, ?rounds: Integer) -> void
|
|
32
|
+
|
|
33
|
+
# A copy of +chain+ with only Robin's own middleware.
|
|
34
|
+
def self.own: (Middleware::Chain chain) -> Middleware::Chain
|
|
35
|
+
|
|
36
|
+
private def self.job: (Client client) -> job_hash
|
|
37
|
+
|
|
38
|
+
private def self.push_bulk: (Client client, Connection conn) -> void
|
|
39
|
+
|
|
40
|
+
private def self.push: (Client client, Connection conn) -> void
|
|
41
|
+
|
|
42
|
+
private def self.fetch_and_run: (Connection fetches, Middleware::Chain server, Connection conn) -> void
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
class Web
|
|
3
|
+
# JSON endpoint handlers. One instance per request; each handler returns
|
|
4
|
+
# the Rack response.
|
|
5
|
+
class API
|
|
6
|
+
SETS: Hash[String, singleton(ScheduledSet) | singleton(RetrySet) | singleton(DeadSet)]
|
|
7
|
+
|
|
8
|
+
SET_ACTIONS: Hash[String, :retry | :delete | :kill]
|
|
9
|
+
|
|
10
|
+
SIGNALS: Hash[String, :quiet! | :stop! | :dump_threads]
|
|
11
|
+
|
|
12
|
+
MAX_CONCURRENCY: Integer
|
|
13
|
+
|
|
14
|
+
FEATURES: Hash[String, bool]
|
|
15
|
+
|
|
16
|
+
# Integer query parameters: name => [default, minimum, maximum].
|
|
17
|
+
INT_PARAMS: Hash[String, [Integer, Integer, Integer]]
|
|
18
|
+
|
|
19
|
+
INFO_FIELDS: Array[String]
|
|
20
|
+
|
|
21
|
+
SEARCH_LIMIT: Integer
|
|
22
|
+
|
|
23
|
+
INFO_LINK: Regexp
|
|
24
|
+
|
|
25
|
+
FAILURE_FIELDS: Array[String]
|
|
26
|
+
|
|
27
|
+
def self.json: (Integer status, json body) -> response
|
|
28
|
+
|
|
29
|
+
# Redis's INFO reply as a Hash.
|
|
30
|
+
def self.parse_info: (String raw) -> Hash[String, String]
|
|
31
|
+
|
|
32
|
+
@env: env
|
|
33
|
+
@request: _Request
|
|
34
|
+
@cluster: String?
|
|
35
|
+
@params: Hash[String, untyped]
|
|
36
|
+
@body: Hash[String, json]?
|
|
37
|
+
|
|
38
|
+
attr_reader config: Config
|
|
39
|
+
|
|
40
|
+
def initialize: (env env, _Request request, String? cluster, Hash[String, untyped] params) -> void
|
|
41
|
+
|
|
42
|
+
# Raises a 403 HttpError unless the request may do +action+.
|
|
43
|
+
def authorize!: (Symbol action, String resource) -> void
|
|
44
|
+
|
|
45
|
+
def session: () -> response
|
|
46
|
+
|
|
47
|
+
def dashboard: () -> response
|
|
48
|
+
|
|
49
|
+
def stats: () -> response
|
|
50
|
+
|
|
51
|
+
# Server-sent events.
|
|
52
|
+
def stream: () -> response
|
|
53
|
+
|
|
54
|
+
def live_stats: () -> Hash[String, untyped]
|
|
55
|
+
|
|
56
|
+
def info: () -> response
|
|
57
|
+
|
|
58
|
+
def queues: () -> response
|
|
59
|
+
|
|
60
|
+
def queue: () -> response
|
|
61
|
+
|
|
62
|
+
def pause_queue: () -> response
|
|
63
|
+
|
|
64
|
+
def unpause_queue: () -> response
|
|
65
|
+
|
|
66
|
+
def pause_class: () -> response
|
|
67
|
+
|
|
68
|
+
# With how many parked jobs went back on their queues.
|
|
69
|
+
def unpause_class: () -> response
|
|
70
|
+
|
|
71
|
+
def clear_queue: () -> response
|
|
72
|
+
|
|
73
|
+
def delete_queue_jobs: () -> response
|
|
74
|
+
|
|
75
|
+
def delete_queue_class: () -> response
|
|
76
|
+
|
|
77
|
+
def busy: () -> response
|
|
78
|
+
|
|
79
|
+
def signal_process: () -> response
|
|
80
|
+
|
|
81
|
+
def resize_process: () -> response
|
|
82
|
+
|
|
83
|
+
def signal_all_processes: () -> response
|
|
84
|
+
|
|
85
|
+
def set: () -> response
|
|
86
|
+
|
|
87
|
+
def set_entry: () -> response
|
|
88
|
+
|
|
89
|
+
def set_bulk: () -> response
|
|
90
|
+
|
|
91
|
+
def set_all: () -> response
|
|
92
|
+
|
|
93
|
+
def edit_entry: () -> response
|
|
94
|
+
|
|
95
|
+
def find_job: () -> response
|
|
96
|
+
|
|
97
|
+
def cancel_job: () -> response
|
|
98
|
+
|
|
99
|
+
def metrics: () -> response
|
|
100
|
+
|
|
101
|
+
def metrics_history: () -> response
|
|
102
|
+
|
|
103
|
+
def metrics_queues: () -> response
|
|
104
|
+
|
|
105
|
+
def metrics_job: () -> response
|
|
106
|
+
|
|
107
|
+
# Deploys in the last +seconds+.
|
|
108
|
+
def deploys: (Integer seconds) -> Array[Hash[String, json]]
|
|
109
|
+
|
|
110
|
+
def batches: () -> response
|
|
111
|
+
|
|
112
|
+
def batch: () -> response
|
|
113
|
+
|
|
114
|
+
def cancel_batch: () -> response
|
|
115
|
+
|
|
116
|
+
def delete_batch: () -> response
|
|
117
|
+
|
|
118
|
+
def limiters: () -> response
|
|
119
|
+
|
|
120
|
+
def reset_limiter: () -> response
|
|
121
|
+
|
|
122
|
+
def delete_limiter: () -> response
|
|
123
|
+
|
|
124
|
+
def cron: () -> response
|
|
125
|
+
|
|
126
|
+
def cron_entry: () -> response
|
|
127
|
+
|
|
128
|
+
def cron_enqueue: () -> response
|
|
129
|
+
|
|
130
|
+
def cron_pause: () -> response
|
|
131
|
+
|
|
132
|
+
def cron_unpause: () -> response
|
|
133
|
+
|
|
134
|
+
def profiles: () -> response
|
|
135
|
+
|
|
136
|
+
# The profile itself, as a download.
|
|
137
|
+
def profile_data: () -> response
|
|
138
|
+
|
|
139
|
+
def delete_profile: () -> response
|
|
140
|
+
|
|
141
|
+
def extension_page: () -> response
|
|
142
|
+
|
|
143
|
+
def extension_data: () -> response
|
|
144
|
+
|
|
145
|
+
def extension_action: () -> response
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def ok: (json body) -> response
|
|
150
|
+
|
|
151
|
+
def stats_event: () -> String
|
|
152
|
+
|
|
153
|
+
def extension!: () -> singleton(Extension)
|
|
154
|
+
|
|
155
|
+
def extension_request: (singleton(Extension) extension, ?Hash[String, json] body) -> Extension::Request
|
|
156
|
+
|
|
157
|
+
# Runs the block; an extension that raises is reported, as a 500.
|
|
158
|
+
def guarded: [T] (singleton(Extension) extension, String what) { () -> T } -> T
|
|
159
|
+
|
|
160
|
+
# The request's JSON body (an object).
|
|
161
|
+
def body: () -> Hash[String, json]
|
|
162
|
+
|
|
163
|
+
def int_param: (String name) -> Integer
|
|
164
|
+
|
|
165
|
+
# [page, per page]
|
|
166
|
+
def paging: () -> [Integer, Integer]
|
|
167
|
+
|
|
168
|
+
def named_queue: () -> Queue
|
|
169
|
+
|
|
170
|
+
def named_class: () -> JobClass
|
|
171
|
+
|
|
172
|
+
def job_set: () -> JobSet
|
|
173
|
+
|
|
174
|
+
def find_entry!: () -> SortedEntry
|
|
175
|
+
|
|
176
|
+
def set_action!: () -> (:retry | :delete | :kill)
|
|
177
|
+
|
|
178
|
+
def live_process: () -> ProcessRecord
|
|
179
|
+
|
|
180
|
+
def signal_method: () -> (:quiet! | :stop! | :dump_threads)
|
|
181
|
+
|
|
182
|
+
# Applies +action+ to +entries+ of +set+; returns how many.
|
|
183
|
+
def apply: (JobSet set, Array[SortedEntry] entries, :retry | :delete | :kill action) -> Integer
|
|
184
|
+
|
|
185
|
+
# The queues' rows, in one round trip.
|
|
186
|
+
def queue_rows: (Hash[String, Integer] sizes) -> Array[Hash[String, untyped]]
|
|
187
|
+
|
|
188
|
+
def job_json: (JobRecord record, ?full: bool) -> Hash[String, json]
|
|
189
|
+
|
|
190
|
+
# The Robin::Web.job_info rows for a job.
|
|
191
|
+
def job_info: (job_hash item) -> Array[Hash[String, String]]
|
|
192
|
+
|
|
193
|
+
def info_row: (String label, untyped value) -> Hash[String, String]
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Robin
|
|
2
|
+
class Web
|
|
3
|
+
# A small JSON endpoint for a batch's progress (mount it apart from the
|
|
4
|
+
# dashboard).
|
|
5
|
+
class BatchStatus
|
|
6
|
+
PATH: Regexp
|
|
7
|
+
|
|
8
|
+
HEADERS: Hash[String, String]
|
|
9
|
+
|
|
10
|
+
@config: Config?
|
|
11
|
+
|
|
12
|
+
# +config+: the Robin config whose batches it shows (Robin.config when
|
|
13
|
+
# nil).
|
|
14
|
+
def initialize: (?config: Config?) -> void
|
|
15
|
+
|
|
16
|
+
def call: (env env) -> response
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def not_found: () -> response
|
|
21
|
+
|
|
22
|
+
def reply: (Integer code, Hash[String, untyped] body, ?Hash[String, String] headers) -> response
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|