robin 0.1.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +372 -0
  3. data/COPYING +674 -0
  4. data/LICENSE +165 -0
  5. data/README.md +1490 -0
  6. data/assets/favicon.svg +31 -0
  7. data/assets/robin-logo.svg +37 -0
  8. data/assets/robin-mono.svg +12 -0
  9. data/assets/robin-wordmark.svg +4 -0
  10. data/assets/robin.svg +34 -0
  11. data/exe/robin +5 -0
  12. data/ext/java/robin_resp/Blocking.java +27 -0
  13. data/ext/java/robin_resp/NativeIO.java +229 -0
  14. data/ext/java/robin_resp/NativeRESP.java +279 -0
  15. data/ext/java/robin_resp/NativeSlots.java +133 -0
  16. data/ext/java/robin_resp/RobinRespService.java +32 -0
  17. data/lib/active_job/queue_adapters/robin_adapter.rb +3 -0
  18. data/lib/generators/robin/install/install_generator.rb +39 -0
  19. data/lib/generators/robin/install/templates/initializer.rb.tt +31 -0
  20. data/lib/generators/robin/install/templates/robin.yml.tt +25 -0
  21. data/lib/generators/robin/job/job_generator.rb +78 -0
  22. data/lib/generators/robin/job/templates/job.rb.tt +13 -0
  23. data/lib/generators/robin/job/templates/job_spec.rb.tt +21 -0
  24. data/lib/generators/robin/job/templates/job_test.rb.tt +21 -0
  25. data/lib/puma/plugin/robin.rb +131 -0
  26. data/lib/robin/active_job.rb +144 -0
  27. data/lib/robin/api.rb +777 -0
  28. data/lib/robin/batch.rb +700 -0
  29. data/lib/robin/cancellation.rb +62 -0
  30. data/lib/robin/cli.rb +325 -0
  31. data/lib/robin/client.rb +372 -0
  32. data/lib/robin/config.rb +461 -0
  33. data/lib/robin/cron.rb +325 -0
  34. data/lib/robin/debounce.rb +108 -0
  35. data/lib/robin/deploy.rb +65 -0
  36. data/lib/robin/embedded.rb +53 -0
  37. data/lib/robin/encryption.rb +147 -0
  38. data/lib/robin/events.rb +60 -0
  39. data/lib/robin/expiry.rb +41 -0
  40. data/lib/robin/fetcher.rb +441 -0
  41. data/lib/robin/gvl.rb +62 -0
  42. data/lib/robin/health.rb +76 -0
  43. data/lib/robin/iterable_job.rb +294 -0
  44. data/lib/robin/job.rb +258 -0
  45. data/lib/robin/job_class.rb +157 -0
  46. data/lib/robin/job_logger.rb +121 -0
  47. data/lib/robin/launcher.rb +658 -0
  48. data/lib/robin/leader.rb +86 -0
  49. data/lib/robin/limiter.rb +639 -0
  50. data/lib/robin/manager.rb +125 -0
  51. data/lib/robin/metrics.rb +303 -0
  52. data/lib/robin/middleware.rb +165 -0
  53. data/lib/robin/opentelemetry.rb +88 -0
  54. data/lib/robin/periodic.rb +327 -0
  55. data/lib/robin/processor.rb +317 -0
  56. data/lib/robin/profiler.rb +140 -0
  57. data/lib/robin/progress.rb +46 -0
  58. data/lib/robin/rails/app_loader.rb +23 -0
  59. data/lib/robin/rails/current_attributes.rb +88 -0
  60. data/lib/robin/rails/error_reporter.rb +31 -0
  61. data/lib/robin/rails/notifications.rb +22 -0
  62. data/lib/robin/rails/railtie.rb +87 -0
  63. data/lib/robin/rails/transactional_push.rb +49 -0
  64. data/lib/robin/rails.rb +23 -0
  65. data/lib/robin/recovery.rb +135 -0
  66. data/lib/robin/redis/connection.rb +639 -0
  67. data/lib/robin/redis/pool.rb +190 -0
  68. data/lib/robin/redis/resp.rb +77 -0
  69. data/lib/robin/reliable_push.rb +153 -0
  70. data/lib/robin/retrier.rb +284 -0
  71. data/lib/robin/scheduler.rb +102 -0
  72. data/lib/robin/scripts.rb +331 -0
  73. data/lib/robin/statsd.rb +135 -0
  74. data/lib/robin/swarm.rb +319 -0
  75. data/lib/robin/systemd.rb +47 -0
  76. data/lib/robin/testing.rb +158 -0
  77. data/lib/robin/top.rb +178 -0
  78. data/lib/robin/unique.rb +198 -0
  79. data/lib/robin/version.rb +5 -0
  80. data/lib/robin/warmup.rb +94 -0
  81. data/lib/robin/web/api.rb +580 -0
  82. data/lib/robin/web/batch_status.rb +44 -0
  83. data/lib/robin/web/dist/assets/ar-y7v9b75f.js +1 -0
  84. data/lib/robin/web/dist/assets/ar-y7v9b75f.js.gz +0 -0
  85. data/lib/robin/web/dist/assets/bricolage-0qmzcpnj.woff2 +0 -0
  86. data/lib/robin/web/dist/assets/cs-df88mq5e.js +1 -0
  87. data/lib/robin/web/dist/assets/cs-df88mq5e.js.gz +0 -0
  88. data/lib/robin/web/dist/assets/da-kemms74g.js +1 -0
  89. data/lib/robin/web/dist/assets/da-kemms74g.js.gz +0 -0
  90. data/lib/robin/web/dist/assets/de-z8kkqg65.js +1 -0
  91. data/lib/robin/web/dist/assets/de-z8kkqg65.js.gz +0 -0
  92. data/lib/robin/web/dist/assets/es-9ahrrn1s.js +1 -0
  93. data/lib/robin/web/dist/assets/es-9ahrrn1s.js.gz +0 -0
  94. data/lib/robin/web/dist/assets/fa-7r0x28nc.js +1 -0
  95. data/lib/robin/web/dist/assets/fa-7r0x28nc.js.gz +0 -0
  96. data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg +31 -0
  97. data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg.gz +0 -0
  98. data/lib/robin/web/dist/assets/fr-r7mqf3d9.js +1 -0
  99. data/lib/robin/web/dist/assets/fr-r7mqf3d9.js.gz +0 -0
  100. data/lib/robin/web/dist/assets/he-7t46b6rt.js +1 -0
  101. data/lib/robin/web/dist/assets/he-7t46b6rt.js.gz +0 -0
  102. data/lib/robin/web/dist/assets/hi-zj434tx4.js +1 -0
  103. data/lib/robin/web/dist/assets/hi-zj434tx4.js.gz +0 -0
  104. data/lib/robin/web/dist/assets/it-pqc2m7gm.js +1 -0
  105. data/lib/robin/web/dist/assets/it-pqc2m7gm.js.gz +0 -0
  106. data/lib/robin/web/dist/assets/ja-k9rgm1pj.js +1 -0
  107. data/lib/robin/web/dist/assets/ja-k9rgm1pj.js.gz +0 -0
  108. data/lib/robin/web/dist/assets/ko-bxersv91.js +1 -0
  109. data/lib/robin/web/dist/assets/ko-bxersv91.js.gz +0 -0
  110. data/lib/robin/web/dist/assets/main-anw3f6ba.css +1 -0
  111. data/lib/robin/web/dist/assets/main-anw3f6ba.css.gz +0 -0
  112. data/lib/robin/web/dist/assets/main-pdtvjejb.js +7 -0
  113. data/lib/robin/web/dist/assets/main-pdtvjejb.js.gz +0 -0
  114. data/lib/robin/web/dist/assets/main-zz8zzhwn.js +2 -0
  115. data/lib/robin/web/dist/assets/main-zz8zzhwn.js.gz +0 -0
  116. data/lib/robin/web/dist/assets/nb-fjnc5064.js +1 -0
  117. data/lib/robin/web/dist/assets/nb-fjnc5064.js.gz +0 -0
  118. data/lib/robin/web/dist/assets/nl-9p8b95b6.js +1 -0
  119. data/lib/robin/web/dist/assets/nl-9p8b95b6.js.gz +0 -0
  120. data/lib/robin/web/dist/assets/pl-8xsrdn8n.js +1 -0
  121. data/lib/robin/web/dist/assets/pl-8xsrdn8n.js.gz +0 -0
  122. data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js +1 -0
  123. data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js.gz +0 -0
  124. data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg +34 -0
  125. data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg.gz +0 -0
  126. data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg +4 -0
  127. data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg.gz +0 -0
  128. data/lib/robin/web/dist/assets/ru-a9ftyw3d.js +1 -0
  129. data/lib/robin/web/dist/assets/ru-a9ftyw3d.js.gz +0 -0
  130. data/lib/robin/web/dist/assets/sv-j9gqamr1.js +1 -0
  131. data/lib/robin/web/dist/assets/sv-j9gqamr1.js.gz +0 -0
  132. data/lib/robin/web/dist/assets/tr-y9z0q51g.js +1 -0
  133. data/lib/robin/web/dist/assets/tr-y9z0q51g.js.gz +0 -0
  134. data/lib/robin/web/dist/assets/uk-2dr9ew3p.js +1 -0
  135. data/lib/robin/web/dist/assets/uk-2dr9ew3p.js.gz +0 -0
  136. data/lib/robin/web/dist/assets/ur-h25nzq1s.js +1 -0
  137. data/lib/robin/web/dist/assets/ur-h25nzq1s.js.gz +0 -0
  138. data/lib/robin/web/dist/assets/vi-9y2ff1bd.js +1 -0
  139. data/lib/robin/web/dist/assets/vi-9y2ff1bd.js.gz +0 -0
  140. data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js +1 -0
  141. data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js.gz +0 -0
  142. data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js +1 -0
  143. data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js.gz +0 -0
  144. data/lib/robin/web/dist/index.html +19 -0
  145. data/lib/robin/web/extension.rb +193 -0
  146. data/lib/robin/web/permissions.rb +40 -0
  147. data/lib/robin/web/prometheus.rb +79 -0
  148. data/lib/robin/web/router.rb +150 -0
  149. data/lib/robin/web/static.rb +110 -0
  150. data/lib/robin/web.rb +196 -0
  151. data/lib/robin.rb +261 -0
  152. data/lib/robin_resp/robin_resp.jar +0 -0
  153. data/sig/manifest.yaml +9 -0
  154. data/sig/robin/api.rbs +442 -0
  155. data/sig/robin/batch.rbs +292 -0
  156. data/sig/robin/cancellation.rbs +25 -0
  157. data/sig/robin/cli.rbs +102 -0
  158. data/sig/robin/client.rbs +118 -0
  159. data/sig/robin/config.rbs +341 -0
  160. data/sig/robin/cron.rbs +149 -0
  161. data/sig/robin/debounce.rbs +36 -0
  162. data/sig/robin/deploy.rbs +24 -0
  163. data/sig/robin/embedded.rbs +25 -0
  164. data/sig/robin/encryption.rbs +49 -0
  165. data/sig/robin/events.rbs +10 -0
  166. data/sig/robin/expiry.rbs +17 -0
  167. data/sig/robin/fetcher.rbs +134 -0
  168. data/sig/robin/gvl.rbs +39 -0
  169. data/sig/robin/health.rbs +30 -0
  170. data/sig/robin/iterable_job.rbs +99 -0
  171. data/sig/robin/job.rbs +173 -0
  172. data/sig/robin/job_class.rbs +55 -0
  173. data/sig/robin/job_logger.rbs +56 -0
  174. data/sig/robin/launcher.rbs +191 -0
  175. data/sig/robin/leader.rbs +43 -0
  176. data/sig/robin/limiter.rbs +317 -0
  177. data/sig/robin/manager.rbs +54 -0
  178. data/sig/robin/metrics.rbs +122 -0
  179. data/sig/robin/middleware.rbs +106 -0
  180. data/sig/robin/opentelemetry.rbs +51 -0
  181. data/sig/robin/periodic.rbs +81 -0
  182. data/sig/robin/processor.rbs +107 -0
  183. data/sig/robin/profiler.rbs +60 -0
  184. data/sig/robin/progress.rbs +22 -0
  185. data/sig/robin/rails/app_loader.rbs +10 -0
  186. data/sig/robin/rails/current_attributes.rbs +44 -0
  187. data/sig/robin/rails/error_reporter.rbs +21 -0
  188. data/sig/robin/rails/notifications.rbs +9 -0
  189. data/sig/robin/rails/transactional_push.rbs +16 -0
  190. data/sig/robin/rails.rbs +8 -0
  191. data/sig/robin/recovery.rbs +29 -0
  192. data/sig/robin/redis/connection.rbs +224 -0
  193. data/sig/robin/redis/pool.rbs +89 -0
  194. data/sig/robin/redis/resp.rbs +29 -0
  195. data/sig/robin/reliable_push.rbs +77 -0
  196. data/sig/robin/retrier.rbs +72 -0
  197. data/sig/robin/scheduler.rbs +40 -0
  198. data/sig/robin/scripts.rbs +36 -0
  199. data/sig/robin/statsd.rbs +55 -0
  200. data/sig/robin/swarm.rbs +133 -0
  201. data/sig/robin/systemd.rbs +13 -0
  202. data/sig/robin/testing.rbs +80 -0
  203. data/sig/robin/top.rbs +79 -0
  204. data/sig/robin/unique.rbs +72 -0
  205. data/sig/robin/version.rbs +3 -0
  206. data/sig/robin/warmup.rbs +44 -0
  207. data/sig/robin/web/api.rbs +196 -0
  208. data/sig/robin/web/batch_status.rbs +25 -0
  209. data/sig/robin/web/extension.rbs +106 -0
  210. data/sig/robin/web/permissions.rbs +14 -0
  211. data/sig/robin/web/prometheus.rbs +33 -0
  212. data/sig/robin/web/router.rbs +53 -0
  213. data/sig/robin/web/static.rbs +42 -0
  214. data/sig/robin/web.rbs +140 -0
  215. data/sig/robin.rbs +116 -0
  216. data/sig/robin_resp.rbs +55 -0
  217. metadata +294 -0
@@ -0,0 +1,106 @@
1
+ module Robin
2
+ class Web
3
+ # A page of your own in the dashboard (see lib/robin/web/extension.rb).
4
+ class Extension
5
+ # An action's block: the message to show (a String; anything else
6
+ # shows "Done"). It runs on an instance of the extension.
7
+ type action = ^(Request request) [self: Extension] -> untyped
8
+
9
+ # A data block: its value (anything JSON can hold) is the response.
10
+ type data_source = ^(Request request) [self: Extension] -> json
11
+
12
+ SLUG: Regexp
13
+
14
+ # What blocks, actions and data blocks get: the dashboard request.
15
+ class Request < Struct[untyped]
16
+ attr_accessor config: Config
17
+
18
+ # The query parameters.
19
+ attr_accessor params: Hash[String, untyped]
20
+
21
+ attr_accessor env: env
22
+
23
+ # The dashboard's language ("en", "pt-BR"...).
24
+ attr_accessor locale: String
25
+
26
+ # An action's JSON body.
27
+ attr_accessor body: Hash[String, json]
28
+
29
+ attr_accessor extension: singleton(Extension)?
30
+
31
+ def self.new: (Config config, Hash[String, untyped] params, env env, String locale, Hash[String, json] body, singleton(Extension)? extension) -> instance
32
+
33
+ # +text+ in the dashboard's language, with {name} placeholders
34
+ # filled from +values+.
35
+ def t: (String text, **_ToS values) -> String
36
+ end
37
+
38
+ # Each is nil until set (never set back to nil).
39
+ self.@slug: String
40
+ self.@title: String
41
+ self.@actions: Hash[String, action]?
42
+ self.@data_sources: Hash[String, data_source]?
43
+ self.@assets: String
44
+ self.@script: String
45
+ self.@stylesheet: String
46
+ self.@translations: String
47
+ self.@messages: Hash[String, Hash[String, String]]
48
+
49
+ # The page's slug (in its URL); sets it with +value+.
50
+ def self.slug: (?String | Symbol | nil value) -> String
51
+
52
+ # The page's title (its tab); sets it with +value+.
53
+ def self.title: (?String | Symbol | nil value) -> String
54
+
55
+ # Adds an action (a button's) the block runs.
56
+ def self.action: (_ToS name) { (Request request) [self: Extension] -> untyped } -> action
57
+
58
+ def self.actions: () -> Hash[String, action]
59
+
60
+ # A JSON endpoint for the page's script; the block's value is the
61
+ # response.
62
+ def self.data: (_ToS name) { (Request request) [self: Extension] -> json } -> data_source
63
+
64
+ def self.data_sources: () -> Hash[String, data_source]
65
+
66
+ # The directory the page's files are served from; sets it with +dir+.
67
+ def self.assets: (?String? dir) -> String?
68
+
69
+ # The page's JavaScript module, relative to +assets+.
70
+ def self.script: (?String? path) -> String?
71
+
72
+ # The page's stylesheet, relative to +assets+.
73
+ def self.stylesheet: (?String? path) -> String?
74
+
75
+ # The directory of <language>.yml translation files.
76
+ def self.translations: (?String? dir) -> (String | Hash[String, Hash[String, String]] | nil)
77
+
78
+ # English text => translation for +locale+, or nil.
79
+ def self.messages: (String? locale) -> Hash[String, String]?
80
+
81
+ # The full path of an asset, or nil when there's no such file.
82
+ def self.asset_file: (String path) -> String?
83
+
84
+ def self.to_h: () -> Hash[String, untyped]
85
+
86
+ private
87
+
88
+ def self.asset_setting: (Symbol name, String? path) -> String?
89
+
90
+ def self.titles: () -> Hash[String, String]
91
+
92
+ def self.load_messages: (String file) -> Hash[String, String]
93
+
94
+ public
95
+
96
+ # The page's blocks; override this.
97
+ def blocks: (Request request) -> Array[Hash[Symbol | String, json]]
98
+
99
+ # Runs an action; returns the message to show.
100
+ def run: (String name, Request request) -> String
101
+
102
+ # Runs a data block; returns its value.
103
+ def fetch: (String name, Request request) -> json
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,14 @@
1
+ module Robin
2
+ class Web
3
+ # Fine-grained actions passed to Robin::Web.authorize.
4
+ module Permissions
5
+ # Action => what it allows.
6
+ ACTIONS: Hash[Symbol, String]
7
+
8
+ def self.allowed?: (env env, Symbol action, ?String? resource) -> bool
9
+
10
+ # Each action's name => whether it's allowed.
11
+ def self.for: (env env) -> Hash[String, bool]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ module Robin
2
+ class Web
3
+ # Prometheus text exposition at GET /metrics.
4
+ class Prometheus
5
+ # name, type, help, Robin::Stats reader
6
+ STATS: Array[[String, String, String, Symbol]]
7
+
8
+ # name, type, help
9
+ QUEUE_SIZE: [String, String, String]
10
+
11
+ QUEUE_LATENCY: [String, String, String]
12
+
13
+ GVL: [String, String, String]
14
+
15
+ @env: env
16
+
17
+ def initialize: (env env) -> void
18
+
19
+ def call: () -> response
20
+
21
+ private
22
+
23
+ # [labels, size, latency] for every queue in one cluster.
24
+ def queue_samples: (String cluster, Config config, Stats stats) -> Array[[Hash[String, String], Integer, Float]]
25
+
26
+ def header: (String out, String name, String type, String help) -> String
27
+
28
+ def sample: (String out, String name, Hash[String, String] labels, Numeric value) -> String
29
+
30
+ def escape: (String value) -> String
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,53 @@
1
+ module Robin
2
+ class Web
3
+ # Dispatches /api requests to Robin::Web::API, enforcing CSRF and
4
+ # authorization rules.
5
+ class Router
6
+ class Route < Struct[untyped]
7
+ attr_accessor verb: String
8
+ attr_accessor pattern: Regexp
9
+ attr_accessor keys: Array[String]
10
+ # The Robin::Web::API method that handles it.
11
+ attr_accessor handler: Symbol
12
+ # The permission it needs (see Permissions::ACTIONS).
13
+ attr_accessor action: Symbol
14
+
15
+ def self.new: (String verb, Regexp pattern, Array[String] keys, Symbol handler, Symbol action) -> instance
16
+ end
17
+
18
+ class HttpError < StandardError
19
+ attr_reader status: Integer
20
+
21
+ def initialize: (Integer status, String message) -> void
22
+
23
+ def body: () -> Hash[String, String]
24
+ end
25
+
26
+ # verb, path, API method, permission needed.
27
+ ROUTES: Array[[String, String, Symbol, Symbol]]
28
+
29
+ # Actions checked by the handler itself, or not at all.
30
+ SELF_CHECKED: Array[Symbol]
31
+
32
+ SAME_SITE_FETCHES: Array[String]
33
+
34
+ attr_reader routes: Array[Route]
35
+
36
+ def initialize: () -> void
37
+
38
+ def call: (env env) -> response
39
+
40
+ private
41
+
42
+ def compile: (String verb, String path, Symbol handler, Symbol action) -> Route
43
+
44
+ # The route and its decoded path parameters.
45
+ def match: (String verb, String path) -> [Route, Hash[String, String]]?
46
+
47
+ # The requested cluster, or the first one when none is given.
48
+ def cluster_name: (untyped name) -> String?
49
+
50
+ def same_origin?: (_Request request) -> bool
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,42 @@
1
+ module Robin
2
+ class Web
3
+ # Serves the compiled single-page app from lib/robin/web/dist.
4
+ class Static
5
+ TYPES: Hash[String, String]
6
+
7
+ CSP: String
8
+
9
+ SECURITY_HEADERS: Hash[String, String]
10
+
11
+ ASSET_CACHE: String
12
+
13
+ UNBUILT: String
14
+
15
+ @root: String
16
+ @index: String
17
+ @index_mtime: Time
18
+
19
+ def initialize: (String root) -> void
20
+
21
+ def call: (env env) -> response
22
+
23
+ # Serves +file+ (a full path, or nil for a 404).
24
+ def call_file: (env env, String? file) -> response
25
+
26
+ private
27
+
28
+ def not_found: () -> response
29
+
30
+ def respond: (env env) { () -> response } -> response
31
+
32
+ def file: (env env, String file, String cache) -> response
33
+
34
+ def index: (env env) -> response
35
+
36
+ def security_headers: () -> Hash[String, String]
37
+
38
+ # index.html, re-read whenever it changes on disk; nil when unbuilt.
39
+ def index_template: () -> String?
40
+ end
41
+ end
42
+ end
data/sig/robin/web.rbs ADDED
@@ -0,0 +1,140 @@
1
+ module Robin
2
+ # The Robin dashboard: a Rack app serving a single-page UI and the JSON
3
+ # API behind it.
4
+ class Web
5
+ # A Rack env.
6
+ type env = Hash[String, untyped]
7
+
8
+ # What the dashboard uses of a Rack::Request (Robin doesn't depend on
9
+ # Rack, so its signatures can't name it).
10
+ interface _Request
11
+ def head?: () -> bool
12
+
13
+ def request_method: () -> String
14
+
15
+ def path_info: () -> String
16
+
17
+ # The query parameters.
18
+ def GET: () -> Hash[String, untyped]
19
+
20
+ def get_header: (String name) -> untyped
21
+
22
+ def base_url: () -> String
23
+
24
+ # The request's body (rack.input), if it has one.
25
+ def body: () -> _Reader?
26
+ end
27
+
28
+ interface _Reader
29
+ def read: () -> String?
30
+ end
31
+
32
+ # A Rack response: status, headers and body.
33
+ type response = [Integer, Hash[String, String], _Each[String]]
34
+
35
+ # Robin::Web.authorize's block: truthy to allow +action+ on +resource+
36
+ # (any value: only its truthiness counts).
37
+ type authorizer = ^(env env, Symbol action, String? resource) -> untyped
38
+
39
+ # A Robin::Web.job_info block: the row's text (anything with #to_s), a
40
+ # Hash with :text and :href, or nil to leave the row out.
41
+ type job_info_row = ^(job_hash job) -> untyped
42
+
43
+ DIST: String
44
+
45
+ ASSETS_PATH: Regexp
46
+
47
+ self.@title: String
48
+ self.@brand_color: String?
49
+ self.@read_only: bool
50
+ self.@stream_interval: Numeric
51
+ self.@stream_lifetime: Numeric
52
+ self.@live_updates: :poll | :stream
53
+ self.@assets_path: String?
54
+ self.@clusters: Hash[String, Config]?
55
+ self.@authorizer: authorizer?
56
+ self.@extensions: Hash[String, singleton(Extension)]?
57
+ self.@job_info_rows: Hash[String, job_info_row]?
58
+ self.@app: Web?
59
+
60
+ def self.title: () -> String
61
+
62
+ def self.title=: (String) -> String
63
+
64
+ # The dashboard's accent color (a CSS color), or nil for the default.
65
+ def self.brand_color: () -> String?
66
+
67
+ def self.brand_color=: (String?) -> String?
68
+
69
+ def self.read_only: () -> bool
70
+
71
+ def self.read_only=: (bool) -> bool
72
+
73
+ # Seconds between live updates.
74
+ def self.stream_interval: () -> Numeric
75
+
76
+ def self.stream_interval=: (Numeric) -> Numeric
77
+
78
+ # Seconds a stream stays open before the browser reconnects.
79
+ def self.stream_lifetime: () -> Numeric
80
+
81
+ def self.stream_lifetime=: (Numeric) -> Numeric
82
+
83
+ # :poll (default) or :stream.
84
+ def self.live_updates: () -> (:poll | :stream)
85
+
86
+ def self.live_updates=: (:poll | :stream) -> (:poll | :stream)
87
+
88
+ # Where browsers load the dashboard's assets from: an http(s) URL or a
89
+ # path on this host, ending in "/"; nil serves them from the dashboard.
90
+ def self.assets_path: () -> String?
91
+
92
+ def self.assets_path=: (_ToS? value) -> void
93
+
94
+ # Named Robin configs, one per Redis cluster.
95
+ def self.clusters: () -> Hash[String, Config]
96
+
97
+ def self.clusters=: (Hash[String | Symbol, Config] hash) -> void
98
+
99
+ # Registers an authorization callback.
100
+ def self.authorize: () { (env env, Symbol action, String? resource) -> untyped } -> authorizer
101
+
102
+ def self.authorizer: () -> authorizer?
103
+
104
+ # Adds a page of your own (a Robin::Web::Extension subclass).
105
+ def self.register: (singleton(Extension) extension) -> singleton(Extension)
106
+
107
+ # Registered extensions by slug.
108
+ def self.extensions: () -> Hash[String, singleton(Extension)]
109
+
110
+ # Adds a row to every job's detail page.
111
+ def self.job_info: (_ToS label) { (job_hash job) -> untyped } -> job_info_row
112
+
113
+ # The job_info blocks by label.
114
+ def self.job_info_rows: () -> Hash[String, job_info_row]
115
+
116
+ def self.call: (env env) -> response
117
+
118
+ def self.app: () -> Web
119
+
120
+ # Restores default settings (used by tests).
121
+ def self.reset!: () -> void
122
+
123
+ @router: Router
124
+ @static: Static
125
+
126
+ def initialize: () -> void
127
+
128
+ def call: (env env) -> response
129
+
130
+ # GET /health: pings every cluster's Redis.
131
+ def health: () -> response
132
+
133
+ # GET /extensions/<slug>/<file>: a file from an extension's assets.
134
+ def extension_asset: (env env, String path) -> response
135
+
136
+ private
137
+
138
+ def monotonic_ms: () -> Float
139
+ end
140
+ end
data/sig/robin.rbs ADDED
@@ -0,0 +1,116 @@
1
+ # Robin: fast, reliable background jobs for Ruby.
2
+ module Robin
3
+ # A job as Robin stores it: a JSON object, string keys ("class", "args",
4
+ # "jid", "queue", "created_at"...). Its values are whatever JSON holds
5
+ # (and, before a push is normalized, whatever the caller passed).
6
+ type job_hash = Hash[String, untyped]
7
+
8
+ # A value parsed from JSON, or one that's about to be generated as JSON:
9
+ # anything JSON can hold.
10
+ type json = untyped
11
+
12
+ # A job's class as a push or a periodic job names it: the class itself,
13
+ # or its name.
14
+ type job_class = Class | String
15
+
16
+ # The environment's variables: ENV, or a Hash standing in for it.
17
+ interface _Env
18
+ def []: (String name) -> String?
19
+ end
20
+
21
+ NAME: String
22
+
23
+ JID_BATCH: Integer
24
+
25
+ # A thread's random hex digits for job ids, and how far it has used them.
26
+ class JidBatch < Struct[String | Integer]
27
+ attr_accessor hex: String
28
+ attr_accessor offset: Integer
29
+ attr_accessor pid: Integer
30
+
31
+ def self.new: (String hex, Integer offset, Integer pid) -> instance
32
+ end
33
+
34
+ class Error < StandardError
35
+ end
36
+
37
+ # Raised by a job to stop immediately without retrying.
38
+ class Discard < Error
39
+ end
40
+
41
+ # Raised inside worker threads when the server's shutdown timeout elapses.
42
+ class Shutdown < Interrupt
43
+ end
44
+
45
+ self.@config: Config?
46
+ self.@server: true?
47
+
48
+ def self.config: () -> Config
49
+
50
+ def self.config=: (Config) -> Config
51
+
52
+ # Loads every autoloaded part of Robin up front (except Robin::Testing).
53
+ def self.eager_load!: () -> void
54
+
55
+ # Configure Robin for every process (client and server).
56
+ def self.configure: [T] () { (Config config) -> T } -> T
57
+
58
+ # Configure Robin only inside a job-processing server.
59
+ def self.configure_server: [T] () { (Config config) -> T } -> T?
60
+
61
+ # Configure Robin only inside non-server processes (web, console, rake).
62
+ def self.configure_client: [T] () { (Config config) -> T } -> T?
63
+
64
+ def self.server?: () -> bool
65
+
66
+ def self.server!: () -> true
67
+
68
+ # Runs a Robin server inside the current process (e.g. alongside Puma).
69
+ def self.configure_embed: () ?{ (Config config) -> void } -> Embedded
70
+
71
+ def self.redis: [T] () { (Redis::Connection conn) -> T } -> T
72
+
73
+ def self.hostname: (?env: _Env) -> String
74
+
75
+ def self.logger: () -> Logger
76
+
77
+ def self.dump_json: (json obj) -> String
78
+
79
+ def self.load_json: (String str) -> json
80
+
81
+ # The job as it was stored in Redis, before middleware or the job itself
82
+ # changed anything.
83
+ def self.pristine: (job_hash payload) -> job_hash
84
+
85
+ # Whether +exception+ is Robin::Shutdown or was caused by it.
86
+ def self.shutdown?: (Exception? exception) -> bool
87
+
88
+ # Marks +payload+ as parsed from +raw+ (see #pristine).
89
+ def self.remember_raw: [T < Object] (T payload, String raw) -> T
90
+
91
+ # Returns +string+ as valid UTF-8.
92
+ def self.utf8: (String string) -> String
93
+
94
+ # Epoch milliseconds (wall clock).
95
+ def self.now_ms: () -> Integer
96
+
97
+ def self.epoch_seconds: (Integer | Float ms) -> Float
98
+
99
+ def self.epoch_ms: (Integer | Float | Rational | String seconds) -> Integer
100
+
101
+ # The class a job shows as.
102
+ def self.display_class: (job_hash payload) -> String
103
+
104
+ # A job's epoch-ms timestamp as epoch ms (also from epoch seconds).
105
+ def self.ms_of: (Integer | Float time) -> (Integer | Float)
106
+ | (nil time) -> nil
107
+
108
+ # A job id: 24 random hex digits.
109
+ def self.generate_jid: () -> String
110
+
111
+ # Is this process currently holding cluster leadership?
112
+ def self.leader?: () -> bool
113
+
114
+ # Requests cancellation of jobs (one or more jids).
115
+ def self.cancel!: (*String jids, ?ttl: Integer) -> void
116
+ end
@@ -0,0 +1,55 @@
1
+ # The optional native extension (robin_resp/robin_resp): C on CRuby
2
+ # (ext/robin_resp), Java on JRuby (ext/java). Robin falls back to pure Ruby
3
+ # without it.
4
+ module Robin
5
+ module Redis
6
+ # The extension's RESP2 parser and encoder (C and Java): what
7
+ # Robin::Redis::RESP does, faster.
8
+ module NativeRESP
9
+ # [value, next_pos], or nil while +buf+ doesn't yet hold a whole reply
10
+ # at +pos+. Error replies are returned as CommandErrors.
11
+ def self?.parse: (String buf, Integer pos) -> [reply, Integer]?
12
+
13
+ # Appends the command +args+ to +out+ and returns +out+.
14
+ def self?.encode: (command args, ?String out) -> String
15
+ end
16
+
17
+ # The extension's socket reader (C where poll(2) exists, and Java).
18
+ module NativeIO
19
+ # Appends what arrives on +io+ within +timeout+ seconds to +buffer+:
20
+ # how many bytes, nil when the server closed the connection, or false
21
+ # when nothing arrived in time.
22
+ def self?.fill: (IO io, String buffer, seconds timeout) -> (Integer | false | nil)
23
+
24
+ # Whether a connection between commands can't be used.
25
+ def self?.stale?: (IO io) -> bool
26
+
27
+ # Sends +data+ and reads the start of the replies into +buffer+ (C
28
+ # only): what #fill returns, :stale (having sent nothing), or
29
+ # [bytes written, errno] (a nil errno for a write that timed out).
30
+ def self?.roundtrip: (IO io, String data, String buffer, seconds write_timeout, seconds read_timeout) -> (Integer | false | nil | :stale | [Integer, Integer?])
31
+ end
32
+
33
+ # The Java extension's lock-free pool bookkeeping (JRuby only).
34
+ class NativeSlots
35
+ include Pool::_Slots
36
+
37
+ def initialize: (Integer size) -> void
38
+ end
39
+ end
40
+
41
+ # The total time threads have waited for the GVL (C, on Rubies with thread
42
+ # event hooks).
43
+ module NativeGVL
44
+ # Starts measuring (again); a no-op while measuring.
45
+ def self?.start: () -> nil
46
+
47
+ # Stops measuring; the total stays.
48
+ def self?.stop: () -> nil
49
+
50
+ def self?.running?: () -> bool
51
+
52
+ # Nanoseconds all threads have waited for the GVL while measuring.
53
+ def self?.wait_ns: () -> Integer
54
+ end
55
+ end