zizq 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/LICENSE +21 -0
- data/README.md +94 -0
- data/bin/profile-worker +145 -0
- data/bin/zizq-worker +174 -0
- data/lib/active_job/queue_adapters/zizq_adapter.rb +109 -0
- data/lib/zizq/ack_processor.rb +132 -0
- data/lib/zizq/active_job_config.rb +122 -0
- data/lib/zizq/backoff.rb +50 -0
- data/lib/zizq/bulk_enqueue.rb +87 -0
- data/lib/zizq/client.rb +982 -0
- data/lib/zizq/configuration.rb +164 -0
- data/lib/zizq/enqueue_request.rb +178 -0
- data/lib/zizq/enqueue_with.rb +109 -0
- data/lib/zizq/error.rb +43 -0
- data/lib/zizq/job.rb +188 -0
- data/lib/zizq/job_config.rb +244 -0
- data/lib/zizq/lifecycle.rb +58 -0
- data/lib/zizq/middleware.rb +79 -0
- data/lib/zizq/query.rb +566 -0
- data/lib/zizq/resources/error_enumerator.rb +241 -0
- data/lib/zizq/resources/error_page.rb +19 -0
- data/lib/zizq/resources/error_record.rb +19 -0
- data/lib/zizq/resources/job.rb +124 -0
- data/lib/zizq/resources/job_page.rb +57 -0
- data/lib/zizq/resources/page.rb +77 -0
- data/lib/zizq/resources/resource.rb +45 -0
- data/lib/zizq/resources.rb +16 -0
- data/lib/zizq/version.rb +9 -0
- data/lib/zizq/worker.rb +467 -0
- data/lib/zizq.rb +269 -0
- data/sig/generated/zizq/ack_processor.rbs +73 -0
- data/sig/generated/zizq/active_job_config.rbs +74 -0
- data/sig/generated/zizq/backoff.rbs +34 -0
- data/sig/generated/zizq/bulk_enqueue.rbs +72 -0
- data/sig/generated/zizq/client.rbs +419 -0
- data/sig/generated/zizq/configuration.rbs +95 -0
- data/sig/generated/zizq/enqueue_request.rbs +94 -0
- data/sig/generated/zizq/enqueue_with.rbs +88 -0
- data/sig/generated/zizq/error.rbs +41 -0
- data/sig/generated/zizq/job.rbs +136 -0
- data/sig/generated/zizq/job_config.rbs +150 -0
- data/sig/generated/zizq/lifecycle.rbs +34 -0
- data/sig/generated/zizq/middleware.rbs +50 -0
- data/sig/generated/zizq/query.rbs +327 -0
- data/sig/generated/zizq/resources/error_enumerator.rbs +148 -0
- data/sig/generated/zizq/resources/error_page.rbs +13 -0
- data/sig/generated/zizq/resources/error_record.rbs +20 -0
- data/sig/generated/zizq/resources/job.rbs +89 -0
- data/sig/generated/zizq/resources/job_page.rbs +33 -0
- data/sig/generated/zizq/resources/page.rbs +47 -0
- data/sig/generated/zizq/resources/resource.rbs +26 -0
- data/sig/generated/zizq/version.rbs +5 -0
- data/sig/generated/zizq/worker.rbs +152 -0
- data/sig/generated/zizq.rbs +180 -0
- data/sig/zizq.rbs +111 -0
- metadata +134 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
# Generated from lib/zizq/client.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Zizq
|
|
4
|
+
# Low-level HTTP wrapper for the Zizq job queue server API.
|
|
5
|
+
#
|
|
6
|
+
# Supports both JSON and MessagePack serialization formats, determined at
|
|
7
|
+
# construction time.
|
|
8
|
+
#
|
|
9
|
+
# HTTP requests are dispatched through a persistent background IO thread
|
|
10
|
+
# when called from non-Async contexts, keeping the HTTP/2 connection alive
|
|
11
|
+
# across calls and avoiding ephemeral port exhaustion. When called from
|
|
12
|
+
# within an existing Async reactor, the shared HTTP client is used directly.
|
|
13
|
+
class Client
|
|
14
|
+
# A fully-read HTTP response (status + decoded body), safe to use outside
|
|
15
|
+
# the async reactor that produced it.
|
|
16
|
+
class RawResponse < Data
|
|
17
|
+
attr_reader status(): untyped
|
|
18
|
+
|
|
19
|
+
attr_reader body(): untyped
|
|
20
|
+
|
|
21
|
+
attr_reader content_type(): untyped
|
|
22
|
+
|
|
23
|
+
def self.new: (untyped status, untyped body, untyped content_type) -> instance
|
|
24
|
+
| (status: untyped, body: untyped, content_type: untyped) -> instance
|
|
25
|
+
|
|
26
|
+
def self.members: () -> [ :status, :body, :content_type ]
|
|
27
|
+
|
|
28
|
+
def members: () -> [ :status, :body, :content_type ]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
CONTENT_TYPES: untyped
|
|
32
|
+
|
|
33
|
+
STREAM_ACCEPT: untyped
|
|
34
|
+
|
|
35
|
+
# The base URL of the Zizq server (e.g. "https://localhost:7890")
|
|
36
|
+
attr_reader url: String
|
|
37
|
+
|
|
38
|
+
# The message format to use for all communication between the client and
|
|
39
|
+
# the server (default = `:msgpack`).
|
|
40
|
+
attr_reader format: Zizq::format
|
|
41
|
+
|
|
42
|
+
# Initialize a new instance of the client with the given base URL and
|
|
43
|
+
# optional format options.
|
|
44
|
+
#
|
|
45
|
+
# @rbs url: String
|
|
46
|
+
# @rbs format: Zizq::format
|
|
47
|
+
# @rbs ssl_context: OpenSSL::SSL::SSLContext?
|
|
48
|
+
# @rbs return: void
|
|
49
|
+
def initialize: (url: String, ?format: Zizq::format, ?ssl_context: OpenSSL::SSL::SSLContext?) -> void
|
|
50
|
+
|
|
51
|
+
# Close all thread-local HTTP clients and release connections.
|
|
52
|
+
def close: () -> untyped
|
|
53
|
+
|
|
54
|
+
def cleanup_internal_clients: () -> untyped
|
|
55
|
+
|
|
56
|
+
# Enqueue a new job.
|
|
57
|
+
#
|
|
58
|
+
# This is a low-level primitive that makes a direct API call to the server
|
|
59
|
+
# using the Zizq API's expected inputs. Callers should generally use
|
|
60
|
+
# [`Zizq::enqueue`] instead.
|
|
61
|
+
#
|
|
62
|
+
# Returns a resource instance of the new job wrapping the API response.
|
|
63
|
+
#
|
|
64
|
+
# @rbs queue: String
|
|
65
|
+
# @rbs type: String
|
|
66
|
+
# @rbs payload: Hash[String | Symbol, untyped]
|
|
67
|
+
# @rbs priority: Integer?
|
|
68
|
+
# @rbs ready_at: Zizq::to_f?
|
|
69
|
+
# @rbs retry_limit: Integer?
|
|
70
|
+
# @rbs backoff: Zizq::backoff?
|
|
71
|
+
# @rbs retention: Zizq::retention?
|
|
72
|
+
# @rbs unique_key: String?
|
|
73
|
+
# @rbs unique_while: Zizq::unique_scope?
|
|
74
|
+
# @rbs return: Resources::Job
|
|
75
|
+
def enqueue: (queue: String, type: String, payload: Hash[String | Symbol, untyped], ?priority: Integer?, ?ready_at: Zizq::to_f?, ?retry_limit: Integer?, ?backoff: Zizq::backoff?, ?retention: Zizq::retention?, ?unique_key: String?, ?unique_while: Zizq::unique_scope?) -> Resources::Job
|
|
76
|
+
|
|
77
|
+
# Enqueue multiple jobs atomically in a single bulk request.
|
|
78
|
+
#
|
|
79
|
+
# This is a low-level primitive that makes a direct API call to the server
|
|
80
|
+
# using the Zizq API's expected inputs. Callers should generally use
|
|
81
|
+
# [`Zizq::enqueue_bulk`] instead.
|
|
82
|
+
#
|
|
83
|
+
# Returns an array of resource instances wrapping the API response.
|
|
84
|
+
#
|
|
85
|
+
# @rbs jobs: Array[Hash[Symbol, untyped]]
|
|
86
|
+
# @rbs return: Array[Resources::Job]
|
|
87
|
+
def enqueue_bulk: (jobs: Array[Hash[Symbol, untyped]]) -> Array[Resources::Job]
|
|
88
|
+
|
|
89
|
+
# Get a single job by ID.
|
|
90
|
+
def get_job: (untyped id) -> untyped
|
|
91
|
+
|
|
92
|
+
# List jobs with optional filters.
|
|
93
|
+
#
|
|
94
|
+
# Multi-value filters (`status`, `queue`, `type`, `id`) accept arrays —
|
|
95
|
+
# they are joined with commas as the server expects.
|
|
96
|
+
#
|
|
97
|
+
# The `filter` parameter accepts a jq expression for filtering jobs by
|
|
98
|
+
# payload content (e.g. `.user_id == 42`).
|
|
99
|
+
#
|
|
100
|
+
# @rbs id: (String | Array[String])?
|
|
101
|
+
# @rbs status: (String | Array[String])?
|
|
102
|
+
# @rbs queue: (String | Array[String])?
|
|
103
|
+
# @rbs type: (String | Array[String])?
|
|
104
|
+
# @rbs filter: String?
|
|
105
|
+
# @rbs from: String?
|
|
106
|
+
# @rbs order: Zizq::sort_direction?
|
|
107
|
+
# @rbs limit: Integer?
|
|
108
|
+
# @rbs return: Resources::JobPage
|
|
109
|
+
def list_jobs: (?id: (String | Array[String])?, ?status: (String | Array[String])?, ?queue: (String | Array[String])?, ?type: (String | Array[String])?, ?filter: String?, ?from: String?, ?order: Zizq::sort_direction?, ?limit: Integer?) -> Resources::JobPage
|
|
110
|
+
|
|
111
|
+
# Delete a single job by ID.
|
|
112
|
+
#
|
|
113
|
+
# @rbs id: String
|
|
114
|
+
# @rbs return: void
|
|
115
|
+
def delete_job: (String id) -> void
|
|
116
|
+
|
|
117
|
+
# Delete jobs matching the given filters.
|
|
118
|
+
#
|
|
119
|
+
# Filters in the `where:` argument use the same keys as `list_jobs`. An
|
|
120
|
+
# empty `where:` hash deletes all jobs.
|
|
121
|
+
#
|
|
122
|
+
# Returns the number of deleted jobs.
|
|
123
|
+
#
|
|
124
|
+
# @rbs where: Zizq::where_params
|
|
125
|
+
# @rbs return: Integer
|
|
126
|
+
def delete_all_jobs: (?where: Zizq::where_params) -> Integer
|
|
127
|
+
|
|
128
|
+
# Update a single job's mutable fields.
|
|
129
|
+
#
|
|
130
|
+
# Fields not provided are left unchanged. Use `Zizq::RESET` to clear
|
|
131
|
+
# a nullable field back to the server default.
|
|
132
|
+
#
|
|
133
|
+
# Raises `Zizq::NotFoundError` if the job does not exist.
|
|
134
|
+
# Raises `Zizq::ClientError` (422) if the job is in a terminal state.
|
|
135
|
+
#
|
|
136
|
+
# @rbs id: String
|
|
137
|
+
# @rbs queue: (String | singleton(Zizq::UNCHANGED))?
|
|
138
|
+
# @rbs priority: (Integer | singleton(Zizq::UNCHANGED))?
|
|
139
|
+
# @rbs ready_at: (Zizq::to_f | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
140
|
+
# @rbs retry_limit: (Integer | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
141
|
+
# @rbs backoff: (Zizq::backoff | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
142
|
+
# @rbs retention: (Zizq::retention | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
143
|
+
# @rbs return: Resources::Job
|
|
144
|
+
def update_job: (String id, ?queue: (String | singleton(Zizq::UNCHANGED))?, ?priority: (Integer | singleton(Zizq::UNCHANGED))?, ?ready_at: (Zizq::to_f | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?retry_limit: (Integer | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?backoff: (Zizq::backoff | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?retention: (Zizq::retention | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?) -> Resources::Job
|
|
145
|
+
|
|
146
|
+
# Update all jobs matching the given filters.
|
|
147
|
+
#
|
|
148
|
+
# Filters in the `where:` argument use the same keys as `list_jobs`.
|
|
149
|
+
# Fields in the `apply:` argument use the same keys as `update_job`.
|
|
150
|
+
#
|
|
151
|
+
# Terminal jobs (completed/dead) are silently skipped unless explicitly
|
|
152
|
+
# requested via `status:` in `where:`, which returns 422.
|
|
153
|
+
#
|
|
154
|
+
# Returns the number of updated jobs.
|
|
155
|
+
#
|
|
156
|
+
# @rbs where: Zizq::where_params
|
|
157
|
+
# @rbs apply: Zizq::apply_params
|
|
158
|
+
# @rbs return: Integer
|
|
159
|
+
def update_all_jobs: (?where: Zizq::where_params, ?apply: Zizq::apply_params) -> Integer
|
|
160
|
+
|
|
161
|
+
# Get a single error record by job ID and attempt number.
|
|
162
|
+
#
|
|
163
|
+
# @rbs id: String
|
|
164
|
+
# @rbs attempt: Integer
|
|
165
|
+
# @rbs return: Resources::ErrorRecord
|
|
166
|
+
def get_error: (String id, attempt: Integer) -> Resources::ErrorRecord
|
|
167
|
+
|
|
168
|
+
# List error records for a job.
|
|
169
|
+
#
|
|
170
|
+
# @rbs id: String
|
|
171
|
+
# @rbs from: String?
|
|
172
|
+
# @rbs order: Zizq::sort_direction?
|
|
173
|
+
# @rbs limit: Integer?
|
|
174
|
+
# @rbs return: Resources::ErrorPage
|
|
175
|
+
def list_errors: (String id, ?from: String?, ?order: Zizq::sort_direction?, ?limit: Integer?) -> Resources::ErrorPage
|
|
176
|
+
|
|
177
|
+
# Health check.
|
|
178
|
+
def health: () -> untyped
|
|
179
|
+
|
|
180
|
+
# Server version string.
|
|
181
|
+
def server_version: () -> untyped
|
|
182
|
+
|
|
183
|
+
# List all distinct queue names on the server.
|
|
184
|
+
def get_queues: () -> untyped
|
|
185
|
+
|
|
186
|
+
# Mark a job as successfully completed (ack).
|
|
187
|
+
#
|
|
188
|
+
# If this method (or [`#report_failure`]) is not called upon job
|
|
189
|
+
# completion, the Zizq server will consider it in-flight and will not
|
|
190
|
+
# send any more jobs if the prefetch limit has been reached, or the
|
|
191
|
+
# server's global in-flight limit has been reached. Jobs must be either
|
|
192
|
+
# acknowledged or failed before new jobs are sent.
|
|
193
|
+
#
|
|
194
|
+
# Jobs are durable and "at least once" delivery is guaranteed. If the
|
|
195
|
+
# client disconnects before it is able to report success or failure the
|
|
196
|
+
# server automatically moves the job back to the queue where it will be
|
|
197
|
+
# provided to another worker. Clients should be prepared to see the same
|
|
198
|
+
# job more than once for this reason.
|
|
199
|
+
#
|
|
200
|
+
# The Zizq server sends heartbeat messages to connected workers so that
|
|
201
|
+
# it can quickly detect and handle disconnected clients.
|
|
202
|
+
def report_success: (untyped id) -> untyped
|
|
203
|
+
|
|
204
|
+
# Bulk-mark jobs as successfully completed (bulk ack).
|
|
205
|
+
#
|
|
206
|
+
# See [`#report_success`] for full details of how acknowledgemen works.
|
|
207
|
+
#
|
|
208
|
+
# There are two ways in which the server can respond successfully:
|
|
209
|
+
#
|
|
210
|
+
# 1. 204 - No Content (All jobs acknowledged)
|
|
211
|
+
# 2. 422 - Unprocessible Entity (Some jobs were not found)
|
|
212
|
+
#
|
|
213
|
+
# Both of these statuses are in reality treated as success because missing
|
|
214
|
+
# jobs have either been previously acknowledged and purged, or moved to
|
|
215
|
+
# some other status that cannot be acknowledged.
|
|
216
|
+
#
|
|
217
|
+
# Other error response types will still raise.
|
|
218
|
+
#
|
|
219
|
+
# @rbs ids: Array[String]
|
|
220
|
+
# @rbs return: nil
|
|
221
|
+
def report_success_bulk: (Array[String] ids) -> nil
|
|
222
|
+
|
|
223
|
+
alias ack_bulk report_success_bulk
|
|
224
|
+
|
|
225
|
+
# Report a job failure (nack).
|
|
226
|
+
#
|
|
227
|
+
# Returns the updated job metadata.
|
|
228
|
+
#
|
|
229
|
+
# If this method is not called when errors occur processing jobs, the
|
|
230
|
+
# Zizq server will consider it in-flight and will not send any more jobs
|
|
231
|
+
# if the prefetch limit has been reached, or the server's global in-flight
|
|
232
|
+
# limit has been reached. Jobs must be either acknowledged or failed before
|
|
233
|
+
# new jobs are sent.
|
|
234
|
+
#
|
|
235
|
+
# Jobs are durable and "at least once" delivery is guaranteed. If the
|
|
236
|
+
# client disconnects before it is able to report success or failure the
|
|
237
|
+
# server automatically moves the job back to the queue where it will be
|
|
238
|
+
# provided to another worker. Clients should be prepared to see the same
|
|
239
|
+
# job more than once for this reason.
|
|
240
|
+
#
|
|
241
|
+
# The Zizq server sends heartbeat messages to connected workers so that
|
|
242
|
+
# it can quickly detect and handle disconnected clients.
|
|
243
|
+
#
|
|
244
|
+
# @rbs id: String
|
|
245
|
+
# @rbs message: String
|
|
246
|
+
# @rbs error_type: String?
|
|
247
|
+
# @rbs backtrace: String?
|
|
248
|
+
# @rbs retry_at: Float?
|
|
249
|
+
# @rbs kill: bool
|
|
250
|
+
# @rbs return: Resources::Job
|
|
251
|
+
def report_failure: (String id, message: String, ?error_type: String?, ?backtrace: String?, ?retry_at: Float?, ?kill: bool) -> Resources::Job
|
|
252
|
+
|
|
253
|
+
# Aliases for ack/nack vs report_success/report_failure.
|
|
254
|
+
alias ack report_success
|
|
255
|
+
|
|
256
|
+
alias nack report_failure
|
|
257
|
+
|
|
258
|
+
# Stream jobs from the server. Yields parsed job hashes.
|
|
259
|
+
#
|
|
260
|
+
# This method does not return unless the server closes the connection or
|
|
261
|
+
# the connection is otherwise interrupted. Jobs are continuously streamed
|
|
262
|
+
# to the client, and when no jobs are available the client waits for new
|
|
263
|
+
# jobs to become ready.
|
|
264
|
+
#
|
|
265
|
+
# If the client does not acknowledge or fail jobs with `[#report_success`]
|
|
266
|
+
# or [`#report_failure`] the server will stop sending new jobs to the
|
|
267
|
+
# client as it hits its prefetch limit.
|
|
268
|
+
#
|
|
269
|
+
# Jobs are durable and "at least once" delivery is guaranteed. If the
|
|
270
|
+
# client disconnects before it is able to report success or failure the
|
|
271
|
+
# server automatically moves the job back to the queue where it will be
|
|
272
|
+
# provided to another worker. Clients should be prepared to see the same
|
|
273
|
+
# job more than once for this reason.
|
|
274
|
+
#
|
|
275
|
+
# The Zizq server sends periodic heartbeat messages to the client which are
|
|
276
|
+
# silently consumed.
|
|
277
|
+
#
|
|
278
|
+
# Example:
|
|
279
|
+
#
|
|
280
|
+
# client.take_jobs(prefetch: 5) do |job|
|
|
281
|
+
# puts "Got job: #{job.inspect}"
|
|
282
|
+
# client.ack(job.id) # mark the job completed
|
|
283
|
+
# end
|
|
284
|
+
#
|
|
285
|
+
# @rbs prefetch: Integer
|
|
286
|
+
# @rbs queues: Array[String]
|
|
287
|
+
# @rbs worker_id: String?
|
|
288
|
+
# @rbs &block: (Resources::Job) -> void
|
|
289
|
+
# @rbs return: void
|
|
290
|
+
def take_jobs: (?prefetch: Integer, ?queues: Array[String], ?worker_id: String?, ?on_connect: untyped, ?on_response: untyped) { (Resources::Job) -> void } -> void
|
|
291
|
+
|
|
292
|
+
# Parse an NDJSON stream from an enumerable of byte chunks.
|
|
293
|
+
#
|
|
294
|
+
# Buffers chunks and splits on newline boundaries. The buffer only
|
|
295
|
+
# ever holds one partial line between extractions, so the `slice!`
|
|
296
|
+
# cost is trivial. Empty lines (heartbeats) are silently skipped.
|
|
297
|
+
def self.parse_ndjson: (untyped chunks) -> untyped
|
|
298
|
+
|
|
299
|
+
# Parse a length-prefixed MessagePack stream from an enumerable of byte
|
|
300
|
+
# chunks.
|
|
301
|
+
#
|
|
302
|
+
# Format: [4-byte big-endian length][MsgPack payload].
|
|
303
|
+
# A zero-length frame is a heartbeat and is silently skipped.
|
|
304
|
+
#
|
|
305
|
+
# Uses StringIO for efficient position-based reading rather than
|
|
306
|
+
# repeatedly slicing from the front of a String (which copies all
|
|
307
|
+
# remaining bytes on every extraction).
|
|
308
|
+
def self.parse_msgpack_stream: (untyped chunks) -> untyped
|
|
309
|
+
|
|
310
|
+
# GET a path on the server and return the decoded response body.
|
|
311
|
+
#
|
|
312
|
+
# The path should include any query parameters already (e.g. pagination
|
|
313
|
+
# links from the server's `pages` object). This is intentionally public
|
|
314
|
+
# so that resource objects like Page can follow links without resorting
|
|
315
|
+
# to `.send`.
|
|
316
|
+
def get_path: (untyped path) -> untyped
|
|
317
|
+
|
|
318
|
+
private
|
|
319
|
+
|
|
320
|
+
# Build a relative path with optional query parameters.
|
|
321
|
+
def build_path: (untyped path, ?params: untyped) -> untyped
|
|
322
|
+
|
|
323
|
+
# Validate and normalize filter parameters for bulk operations.
|
|
324
|
+
#
|
|
325
|
+
# Uses keyword arguments so that unknown keys raise ArgumentError.
|
|
326
|
+
#
|
|
327
|
+
# @rbs id: (String | Array[String])?
|
|
328
|
+
# @rbs status: (String | Array[String])?
|
|
329
|
+
# @rbs queue: (String | Array[String])?
|
|
330
|
+
# @rbs type: (String | Array[String])?
|
|
331
|
+
# @rbs filter: String?
|
|
332
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
333
|
+
def validate_where: (?id: (String | Array[String])?, ?status: (String | Array[String])?, ?queue: (String | Array[String])?, ?type: (String | Array[String])?, ?filter: String?) -> Hash[Symbol, untyped]
|
|
334
|
+
|
|
335
|
+
# Validate set parameters via keyword args (rejects unknown keys) and
|
|
336
|
+
# build the JSON body. Used by `update_all_jobs`.
|
|
337
|
+
#
|
|
338
|
+
# @rbs queue: (String | singleton(Zizq::UNCHANGED))?
|
|
339
|
+
# @rbs priority: (Integer | singleton(Zizq::UNCHANGED))?
|
|
340
|
+
# @rbs ready_at: (Zizq::to_f | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
341
|
+
# @rbs retry_limit: (Integer | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
342
|
+
# @rbs backoff: (Zizq::backoff | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
343
|
+
# @rbs retention: (Zizq::retention | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?
|
|
344
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
345
|
+
def validate_and_build_set: (?queue: (String | singleton(Zizq::UNCHANGED))?, ?priority: (Integer | singleton(Zizq::UNCHANGED))?, ?ready_at: (Zizq::to_f | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?retry_limit: (Integer | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?backoff: (Zizq::backoff | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?, ?retention: (Zizq::retention | singleton(Zizq::RESET) | singleton(Zizq::UNCHANGED))?) -> Hash[Symbol, untyped]
|
|
346
|
+
|
|
347
|
+
# Build the JSON body hash for a PATCH request from set parameters.
|
|
348
|
+
#
|
|
349
|
+
# - `UNCHANGED` values are omitted (field not sent).
|
|
350
|
+
# - `RESET` values are sent as `nil` (JSON null).
|
|
351
|
+
# - `nil` is rejected — use `RESET` to clear a field.
|
|
352
|
+
# - Other values are converted to their wire format.
|
|
353
|
+
#
|
|
354
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
355
|
+
def build_set_body: (?queue: untyped, ?priority: untyped, ?ready_at: untyped, ?retry_limit: untyped, ?backoff: untyped, ?retention: untyped) -> Hash[Symbol, untyped]
|
|
356
|
+
|
|
357
|
+
# Build query params for list endpoints, joining multi-value keys with ",".
|
|
358
|
+
def build_where_params: (untyped options, ?multi_keys: untyped) -> untyped
|
|
359
|
+
|
|
360
|
+
def encode_body: (untyped body) -> untyped
|
|
361
|
+
|
|
362
|
+
def decode_body: (untyped data, ?content_type: untyped) -> untyped
|
|
363
|
+
|
|
364
|
+
# Dispatch a block to the appropriate execution context.
|
|
365
|
+
#
|
|
366
|
+
# If already inside an Async reactor (e.g. AckProcessor, producer),
|
|
367
|
+
# yields the calling thread's HTTP client directly. Otherwise,
|
|
368
|
+
# dispatches via the persistent background IO thread.
|
|
369
|
+
def request: () ?{ (?) -> untyped } -> untyped
|
|
370
|
+
|
|
371
|
+
# Read the response body and close it, returning a RawResponse that is
|
|
372
|
+
# safe to use outside the reactor.
|
|
373
|
+
def consume_response: (untyped response) -> untyped
|
|
374
|
+
|
|
375
|
+
# Push a work block to the background IO thread and block until it
|
|
376
|
+
# completes, returning the result or re-raising any exception.
|
|
377
|
+
def sync_call: () ?{ (?) -> untyped } -> untyped
|
|
378
|
+
|
|
379
|
+
# Lazily start the background IO thread (double-checked locking).
|
|
380
|
+
def ensure_io_thread: () -> untyped
|
|
381
|
+
|
|
382
|
+
# Main loop for the background IO thread. Mirrors AckProcessor: runs an
|
|
383
|
+
# Async reactor, pops work from the queue (fiber-scheduler-aware), and
|
|
384
|
+
# dispatches each call as a concurrent fiber via a barrier.
|
|
385
|
+
def io_thread_run: () -> untyped
|
|
386
|
+
|
|
387
|
+
# Return the calling thread's HTTP client, creating one if needed.
|
|
388
|
+
# Uses thread_variable_get/set (not Thread.current[]) because the
|
|
389
|
+
# latter is fiber-local — each Async fiber would get its own client.
|
|
390
|
+
# The tracking array holds WeakRefs so clients from exited threads
|
|
391
|
+
# can be garbage-collected.
|
|
392
|
+
def http: () -> untyped
|
|
393
|
+
|
|
394
|
+
# Return the calling thread's streaming HTTP client (HTTP/1.1),
|
|
395
|
+
# creating one if needed. See `#http` for the thread-local locking
|
|
396
|
+
# rationale. Kept separate from the main client so the long-lived
|
|
397
|
+
# `/jobs/take` connection doesn't share an HTTP/2 session with
|
|
398
|
+
# ack/enqueue traffic.
|
|
399
|
+
def stream_http: () -> untyped
|
|
400
|
+
|
|
401
|
+
def thread_local_http: (untyped key, untyped endpoint) -> untyped
|
|
402
|
+
|
|
403
|
+
def get: (untyped path, ?params: untyped) -> untyped
|
|
404
|
+
|
|
405
|
+
def post: (untyped path, untyped body) -> untyped
|
|
406
|
+
|
|
407
|
+
def raw_post: (untyped path) -> untyped
|
|
408
|
+
|
|
409
|
+
def delete: (untyped path, ?params: untyped) -> untyped
|
|
410
|
+
|
|
411
|
+
def patch: (untyped path, untyped body, ?params: untyped) -> untyped
|
|
412
|
+
|
|
413
|
+
# Check response status and decode body, raising on errors.
|
|
414
|
+
def handle_response!: (untyped response, expected: untyped) -> untyped
|
|
415
|
+
|
|
416
|
+
# @private
|
|
417
|
+
def self.make_finalizer: (untyped io_queue, untyped http_clients) -> untyped
|
|
418
|
+
end
|
|
419
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Generated from lib/zizq/configuration.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Zizq
|
|
4
|
+
# Global configuration for the Zizq client.
|
|
5
|
+
#
|
|
6
|
+
# The configuration stores only client-level concerns: server URL,
|
|
7
|
+
# serialization format, and logger. Worker-specific settings (queues,
|
|
8
|
+
# threads, etc.) are passed directly to the Worker.
|
|
9
|
+
#
|
|
10
|
+
# See: [`Zizq::configure]`.
|
|
11
|
+
# See: [`Zizq::configuration]`.
|
|
12
|
+
class Configuration
|
|
13
|
+
# Base URL of the Zizq server (default: "http://localhost:7890").
|
|
14
|
+
attr_accessor url: String
|
|
15
|
+
|
|
16
|
+
# Choice of content-type encoding used in communication with the Zizq
|
|
17
|
+
# server.
|
|
18
|
+
#
|
|
19
|
+
# One of: `:json`, `:msgpack` (default)
|
|
20
|
+
attr_accessor format: Zizq::format
|
|
21
|
+
|
|
22
|
+
# Logger instance to which to write log messages.
|
|
23
|
+
attr_accessor logger: Logger
|
|
24
|
+
|
|
25
|
+
# TLS options for connecting to the server over HTTPS.
|
|
26
|
+
#
|
|
27
|
+
# All values may be PEM-encoded strings or file paths.
|
|
28
|
+
#
|
|
29
|
+
# {
|
|
30
|
+
# ca: "path/to/ca-cert.pem", # CA certificate for server verification
|
|
31
|
+
# client_cert: "path/to/client-cert.pem", # Client certificate for mTLS
|
|
32
|
+
# client_key: "path/to/client-key.pem", # Client private key for mTLS
|
|
33
|
+
# }
|
|
34
|
+
#
|
|
35
|
+
# Note: Mutual TLS support requires a Zizq Pro license on the server.
|
|
36
|
+
attr_accessor tls: Zizq::tls_options?
|
|
37
|
+
|
|
38
|
+
# Middleware chain for enqueue. Each middleware receives an
|
|
39
|
+
# `EnqueueRequest` and a chain to continue.
|
|
40
|
+
attr_reader enqueue_middleware: Middleware::Chain[EnqueueRequest, EnqueueRequest]
|
|
41
|
+
|
|
42
|
+
# Middleware chain for dequeue/dispatch. Each middleware receives
|
|
43
|
+
# a `Resources::Job` and a chain to continue.
|
|
44
|
+
attr_reader dequeue_middleware: Middleware::Chain[Resources::Job, void]
|
|
45
|
+
|
|
46
|
+
def initialize: () -> untyped
|
|
47
|
+
|
|
48
|
+
# The job dispatcher.
|
|
49
|
+
# This is the terminal of the dequeue middleware chain.
|
|
50
|
+
# Defaults to `Zizq::Job` which finds and executes jobs written by mixing
|
|
51
|
+
# in the `Zizq::Job` module.
|
|
52
|
+
def dispatcher: () -> untyped
|
|
53
|
+
|
|
54
|
+
# Set the dispatcher to a custom dispatcher implementation.
|
|
55
|
+
#
|
|
56
|
+
# A dispatcher is any object that responds to `#call` with a
|
|
57
|
+
# `Zizq::Resources::Job` instance and performs that job through some
|
|
58
|
+
# application-specific logic.
|
|
59
|
+
#
|
|
60
|
+
# This is the terminal of the dequeue middleware chain.
|
|
61
|
+
#
|
|
62
|
+
# Any errors raised by the dispatcher will result in the normal
|
|
63
|
+
# backoff/retry behaviour. Jobs are acknowledged automatically on success.
|
|
64
|
+
def dispatcher=: (untyped dispatcher) -> untyped
|
|
65
|
+
|
|
66
|
+
# Validates that required configuration is present.
|
|
67
|
+
def validate!: () -> untyped
|
|
68
|
+
|
|
69
|
+
# @private
|
|
70
|
+
# Build an OpenSSL::SSL::SSLContext from the TLS options, or nil if
|
|
71
|
+
# no TLS options are configured.
|
|
72
|
+
def ssl_context: () -> untyped
|
|
73
|
+
|
|
74
|
+
# @private
|
|
75
|
+
# Identity terminal — returns the argument unchanged.
|
|
76
|
+
class Identity
|
|
77
|
+
def call: (untyped arg) -> untyped
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
# @rbs tls: Zizq::tls_options
|
|
83
|
+
def validate_tls!: (Zizq::tls_options tls) -> untyped
|
|
84
|
+
|
|
85
|
+
# Load a certificate from a PEM string or file path.
|
|
86
|
+
def load_cert: (untyped pem_or_path) -> untyped
|
|
87
|
+
|
|
88
|
+
# Load a private key from a PEM string or file path.
|
|
89
|
+
def load_key: (untyped pem_or_path) -> untyped
|
|
90
|
+
|
|
91
|
+
# If the value looks like PEM data, return it as-is; otherwise treat
|
|
92
|
+
# it as a file path and read the contents.
|
|
93
|
+
def resolve_pem: (untyped value) -> untyped
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Generated from lib/zizq/enqueue_request.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Zizq
|
|
4
|
+
# Represents a job enqueue request.
|
|
5
|
+
#
|
|
6
|
+
# Contains all the information needed to enqueue a job. Built by
|
|
7
|
+
# `Job::ClassMethods#zizq_enqueue_options` or directly for raw enqueues.
|
|
8
|
+
# Mutable — callers can override values via the block form of
|
|
9
|
+
# `Zizq.enqueue`.
|
|
10
|
+
#
|
|
11
|
+
# Zizq.enqueue(MyJob, 42) { |req| req.priority = 0 }
|
|
12
|
+
class EnqueueRequest
|
|
13
|
+
# Job type string (e.g. class name).
|
|
14
|
+
attr_accessor type: String
|
|
15
|
+
|
|
16
|
+
# Target queue name.
|
|
17
|
+
attr_accessor queue: String
|
|
18
|
+
|
|
19
|
+
# Job payload (serialized arguments).
|
|
20
|
+
attr_accessor payload: untyped
|
|
21
|
+
|
|
22
|
+
# Job priority (lower = higher priority).
|
|
23
|
+
attr_accessor priority: Integer?
|
|
24
|
+
|
|
25
|
+
# Delay before the job becomes ready (seconds).
|
|
26
|
+
attr_accessor delay: Zizq::to_f?
|
|
27
|
+
|
|
28
|
+
# Absolute time when the job becomes ready (fractional seconds since epoch).
|
|
29
|
+
attr_accessor ready_at: Zizq::to_f?
|
|
30
|
+
|
|
31
|
+
# Maximum number of retries before the job is killed.
|
|
32
|
+
attr_accessor retry_limit: Integer?
|
|
33
|
+
|
|
34
|
+
# Backoff configuration (in seconds).
|
|
35
|
+
attr_accessor backoff: Zizq::backoff?
|
|
36
|
+
|
|
37
|
+
# Retention configuration (in seconds).
|
|
38
|
+
attr_accessor retention: Zizq::retention?
|
|
39
|
+
|
|
40
|
+
# Unique key for deduplication.
|
|
41
|
+
attr_accessor unique_key: String?
|
|
42
|
+
|
|
43
|
+
# Uniqueness scope.
|
|
44
|
+
attr_accessor unique_while: Zizq::unique_scope?
|
|
45
|
+
|
|
46
|
+
# @rbs type: String
|
|
47
|
+
# @rbs queue: String
|
|
48
|
+
# @rbs payload: untyped
|
|
49
|
+
# @rbs priority: Integer?
|
|
50
|
+
# @rbs delay: Zizq::to_f?
|
|
51
|
+
# @rbs ready_at: Zizq::to_f?
|
|
52
|
+
# @rbs retry_limit: Integer?
|
|
53
|
+
# @rbs backoff: Zizq::backoff?
|
|
54
|
+
# @rbs retention: Zizq::retention?
|
|
55
|
+
# @rbs unique_key: String?
|
|
56
|
+
# @rbs unique_while: Zizq::unique_scope?
|
|
57
|
+
# @rbs return: void
|
|
58
|
+
def initialize: (type: String, queue: String, payload: untyped, ?priority: Integer?, ?delay: Zizq::to_f?, ?ready_at: Zizq::to_f?, ?retry_limit: Integer?, ?backoff: Zizq::backoff?, ?retention: Zizq::retention?, ?unique_key: String?, ?unique_while: Zizq::unique_scope?) -> void
|
|
59
|
+
|
|
60
|
+
# Update one or more fields in place.
|
|
61
|
+
#
|
|
62
|
+
# Each keyword argument defaults to the current field value, so
|
|
63
|
+
# callers only need to name the fields they want to change. Returns
|
|
64
|
+
# `self` for chaining. Unknown keys raise `ArgumentError` — this is
|
|
65
|
+
# the signal that prevents typos like `:retries` from silently
|
|
66
|
+
# doing nothing.
|
|
67
|
+
#
|
|
68
|
+
# req.update(priority: 0, ready_at: Time.now + 60)
|
|
69
|
+
#
|
|
70
|
+
# Used by `Zizq::EnqueueWith` to apply scoped overrides, and can be
|
|
71
|
+
# called directly from enqueue blocks as an alternative to assigning
|
|
72
|
+
# individual attributes.
|
|
73
|
+
#
|
|
74
|
+
# @rbs type: String
|
|
75
|
+
# @rbs queue: String
|
|
76
|
+
# @rbs payload: untyped
|
|
77
|
+
# @rbs priority: Integer?
|
|
78
|
+
# @rbs delay: Zizq::to_f?
|
|
79
|
+
# @rbs ready_at: Zizq::to_f?
|
|
80
|
+
# @rbs retry_limit: Integer?
|
|
81
|
+
# @rbs backoff: Zizq::backoff?
|
|
82
|
+
# @rbs retention: Zizq::retention?
|
|
83
|
+
# @rbs unique_key: String?
|
|
84
|
+
# @rbs unique_while: Zizq::unique_scope?
|
|
85
|
+
# @rbs return: self
|
|
86
|
+
def update: (?type: String, ?queue: String, ?payload: untyped, ?priority: Integer?, ?delay: Zizq::to_f?, ?ready_at: Zizq::to_f?, ?retry_limit: Integer?, ?backoff: Zizq::backoff?, ?retention: Zizq::retention?, ?unique_key: String?, ?unique_while: Zizq::unique_scope?) -> self
|
|
87
|
+
|
|
88
|
+
# Convert to the params expected by `Client#enqueue`.
|
|
89
|
+
#
|
|
90
|
+
# Handles seconds -> milliseconds conversion for time-based fields,
|
|
91
|
+
# delay -> ready_at resolution, and nil omission.
|
|
92
|
+
def to_enqueue_params: () -> untyped
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Generated from lib/zizq/enqueue_with.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Zizq
|
|
4
|
+
# A scoped enqueue helper that applies a set of option overrides to every
|
|
5
|
+
# enqueue routed through it.
|
|
6
|
+
#
|
|
7
|
+
# This is sugar for the block form of `Zizq.enqueue`. The two forms below
|
|
8
|
+
# are equivalent:
|
|
9
|
+
#
|
|
10
|
+
# Zizq.enqueue(SendEmailJob, 42) { |req| req.ready_at = Time.now + 3600 }
|
|
11
|
+
# Zizq.enqueue_with(ready_at: Time.now + 3600).enqueue(SendEmailJob, 42)
|
|
12
|
+
#
|
|
13
|
+
# Chainable: successive `enqueue_with` calls merge, with later keys
|
|
14
|
+
# winning:
|
|
15
|
+
#
|
|
16
|
+
# Zizq.enqueue_with(queue: "hi").enqueue_with(priority: 0).enqueue(MyJob)
|
|
17
|
+
#
|
|
18
|
+
# This works inside a bulk block too, applying the overrides to just that one
|
|
19
|
+
# enqueue:
|
|
20
|
+
#
|
|
21
|
+
# Zizq.enqueue_bulk do |b|
|
|
22
|
+
# b.enqueue(MyJob, 1)
|
|
23
|
+
# b.enqueue_with(ready_at: Time.now + 3600).enqueue(OtherJob, 42)
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# Also wraps a whole bulk block when used at the top level, applying the
|
|
27
|
+
# overrides to every job in the batch:
|
|
28
|
+
#
|
|
29
|
+
# Zizq.enqueue_with(priority: 0).enqueue_bulk do |b|
|
|
30
|
+
# b.enqueue(MyJob, 1)
|
|
31
|
+
# b.enqueue(MyJob, 2)
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# A user block is still allowed and runs *after* the overrides, so it can
|
|
35
|
+
# override them further for that one call:
|
|
36
|
+
#
|
|
37
|
+
# Zizq.enqueue_with(priority: 100).enqueue(MyJob) { |req| req.priority = 0 }
|
|
38
|
+
#
|
|
39
|
+
# Instances are immutable — `enqueue_with` returns a new instance. Safe
|
|
40
|
+
# to stash and reuse:
|
|
41
|
+
#
|
|
42
|
+
# high_priority = Zizq.enqueue_with(queue: "hi", priority: 0)
|
|
43
|
+
# high_priority.enqueue(MyJob, 1)
|
|
44
|
+
# high_priority.enqueue(OtherJob, 2)
|
|
45
|
+
class EnqueueWith
|
|
46
|
+
# @rbs target: Zizq::enqueue_target
|
|
47
|
+
# @rbs overrides: Hash[Symbol, untyped]
|
|
48
|
+
# @rbs return: void
|
|
49
|
+
def initialize: (Zizq::enqueue_target target, Hash[Symbol, untyped] overrides) -> void
|
|
50
|
+
|
|
51
|
+
# Merge additional overrides into this scope, returning a new instance.
|
|
52
|
+
# Later keys win.
|
|
53
|
+
#
|
|
54
|
+
# @rbs overrides: Hash[Symbol, untyped]
|
|
55
|
+
# @rbs return: EnqueueWith
|
|
56
|
+
def enqueue_with: (**untyped overrides) -> EnqueueWith
|
|
57
|
+
|
|
58
|
+
# Enqueue a job class via the underlying target, applying the scoped
|
|
59
|
+
# overrides before invoking any caller-supplied block.
|
|
60
|
+
#
|
|
61
|
+
# @rbs job_class: Class & Zizq::job_class
|
|
62
|
+
# @rbs args: Array[untyped]
|
|
63
|
+
# @rbs kwargs: Hash[Symbol, untyped]
|
|
64
|
+
# @rbs &block: ?(EnqueueRequest) -> void
|
|
65
|
+
# @rbs return: untyped
|
|
66
|
+
def enqueue: (Class & Zizq::job_class job_class, *untyped args, **untyped kwargs) ?{ (EnqueueRequest) -> void } -> untyped
|
|
67
|
+
|
|
68
|
+
# Enqueue a raw request via the underlying target, with overrides
|
|
69
|
+
# merged into the kwargs (explicit kwargs take precedence).
|
|
70
|
+
#
|
|
71
|
+
# @rbs queue: String
|
|
72
|
+
# @rbs type: String
|
|
73
|
+
# @rbs payload: untyped
|
|
74
|
+
# @rbs opts: Hash[Symbol, untyped]
|
|
75
|
+
# @rbs return: untyped
|
|
76
|
+
def enqueue_raw: (queue: String, type: String, payload: untyped, **untyped opts) -> untyped
|
|
77
|
+
|
|
78
|
+
# Wrap a bulk block so that every enqueue inside it inherits the
|
|
79
|
+
# scoped overrides. Works uniformly against both the top-level
|
|
80
|
+
# `Zizq` module (starts a new bulk batch) and a `BulkEnqueue`
|
|
81
|
+
# instance (appends to the existing batch), because `BulkEnqueue`
|
|
82
|
+
# implements `enqueue_bulk` as a no-op that yields itself.
|
|
83
|
+
#
|
|
84
|
+
# @rbs &block: (EnqueueWith) -> void
|
|
85
|
+
# @rbs return: untyped
|
|
86
|
+
def enqueue_bulk: () { (EnqueueWith) -> void } -> untyped
|
|
87
|
+
end
|
|
88
|
+
end
|