zizq 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +164 -31
- data/lib/zizq/bulk_enqueue.rb +1 -1
- data/lib/zizq/client.rb +234 -10
- data/lib/zizq/configuration.rb +31 -0
- data/lib/zizq/crontab.rb +263 -0
- data/lib/zizq/crontab_builder.rb +52 -0
- data/lib/zizq/crontab_entry.rb +182 -0
- data/lib/zizq/crontab_entry_builder.rb +133 -0
- data/lib/zizq/enqueue_with.rb +1 -1
- data/lib/zizq/job.rb +6 -2
- data/lib/zizq/query.rb +2 -2
- data/lib/zizq/resources/cron_entry.rb +27 -0
- data/lib/zizq/resources/cron_group.rb +23 -0
- data/lib/zizq/resources/job.rb +4 -36
- data/lib/zizq/resources/job_template.rb +46 -0
- data/lib/zizq/resources.rb +3 -0
- data/lib/zizq/version.rb +1 -1
- data/lib/zizq.rb +109 -19
- data/sig/generated/zizq/bulk_enqueue.rbs +2 -2
- data/sig/generated/zizq/client.rbs +124 -1
- data/sig/generated/zizq/configuration.rbs +21 -0
- data/sig/generated/zizq/crontab.rbs +141 -0
- data/sig/generated/zizq/crontab_builder.rbs +35 -0
- data/sig/generated/zizq/crontab_entry.rbs +98 -0
- data/sig/generated/zizq/crontab_entry_builder.rbs +92 -0
- data/sig/generated/zizq/enqueue_with.rbs +2 -2
- data/sig/generated/zizq/query.rbs +4 -4
- data/sig/generated/zizq/resources/cron_entry.rbs +29 -0
- data/sig/generated/zizq/resources/cron_group.rbs +21 -0
- data/sig/generated/zizq/resources/job.rbs +4 -26
- data/sig/generated/zizq/resources/job_template.rbs +31 -0
- data/sig/generated/zizq.rbs +78 -4
- data/sig/zizq.rbs +24 -17
- metadata +34 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2026 Chris Corbyn <chris@zizq.io>
|
|
2
|
+
# Licensed under the MIT License. See LICENSE file for details.
|
|
3
|
+
|
|
4
|
+
# rbs_inline: enabled
|
|
5
|
+
# frozen_string_literal: true
|
|
6
|
+
|
|
7
|
+
module Zizq
|
|
8
|
+
module Resources
|
|
9
|
+
# Typed wrapper around a cron group response hash.
|
|
10
|
+
class CronGroup < Resource
|
|
11
|
+
def name = @data["name"] #: () -> String
|
|
12
|
+
def paused = @data["paused"] #: () -> bool
|
|
13
|
+
def paused? = paused #: () -> bool
|
|
14
|
+
def paused_at = ms_to_seconds(@data["paused_at"]) #: () -> Float?
|
|
15
|
+
def resumed_at = ms_to_seconds(@data["resumed_at"]) #: () -> Float?
|
|
16
|
+
|
|
17
|
+
# Returns the entries in this group as typed resources.
|
|
18
|
+
def entries #: () -> Array[CronEntry]
|
|
19
|
+
(@data["entries"] || []).map { |e| CronEntry.new(client, e) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/zizq/resources/job.rb
CHANGED
|
@@ -8,51 +8,19 @@ module Zizq
|
|
|
8
8
|
module Resources
|
|
9
9
|
# Typed wrapper around a job response hash.
|
|
10
10
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
class Job <
|
|
11
|
+
# Inherits template fields (type, queue, priority, payload, backoff,
|
|
12
|
+
# retention, unique_key, unique_while) from JobTemplate and adds
|
|
13
|
+
# lifecycle fields and action methods.
|
|
14
|
+
class Job < JobTemplate
|
|
15
15
|
def id = @data["id"] #: () -> String
|
|
16
|
-
def type = @data["type"] #: () -> String
|
|
17
|
-
def queue = @data["queue"] #: () -> String
|
|
18
|
-
def priority = @data["priority"] #: () -> Integer
|
|
19
16
|
def status = @data["status"] #: () -> String
|
|
20
17
|
def ready_at = ms_to_seconds(@data["ready_at"]) #: () -> Float?
|
|
21
18
|
def attempts = @data["attempts"] #: () -> Integer
|
|
22
|
-
def payload = @data["payload"] #: () -> Hash[String, untyped]?
|
|
23
19
|
def dequeued_at = ms_to_seconds(@data["dequeued_at"]) #: () -> Float?
|
|
24
20
|
def failed_at = ms_to_seconds(@data["failed_at"]) #: () -> Float?
|
|
25
21
|
def completed_at = ms_to_seconds(@data["completed_at"]) #: () -> Float?
|
|
26
|
-
def retry_limit = @data["retry_limit"] #: () -> Integer?
|
|
27
|
-
def unique_key = @data["unique_key"] #: () -> String?
|
|
28
|
-
def unique_while = @data["unique_while"]&.to_sym #: () -> Zizq::unique_scope?
|
|
29
22
|
def duplicate? = @data["duplicate"] == true #: () -> bool
|
|
30
23
|
|
|
31
|
-
# Backoff configuration converted from the wire format (ms) to the
|
|
32
|
-
# Ruby-idiomatic format (seconds), matching the Zizq::backoff type.
|
|
33
|
-
def backoff #: () -> Zizq::backoff?
|
|
34
|
-
raw = @data["backoff"]
|
|
35
|
-
return nil unless raw
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
exponent: raw["exponent"].to_f,
|
|
39
|
-
base: raw["base_ms"] / 1000.0,
|
|
40
|
-
jitter: raw["jitter_ms"] / 1000.0
|
|
41
|
-
}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Retention configuration converted from the wire format (ms) to the
|
|
45
|
-
# Ruby-idiomatic format (seconds), matching the Zizq::retention type.
|
|
46
|
-
def retention #: () -> Zizq::retention?
|
|
47
|
-
raw = @data["retention"]
|
|
48
|
-
return nil unless raw
|
|
49
|
-
|
|
50
|
-
result = {} #: Hash[Symbol, Float]
|
|
51
|
-
result[:completed] = raw["completed_ms"] / 1000.0 if raw["completed_ms"]
|
|
52
|
-
result[:dead] = raw["dead_ms"] / 1000.0 if raw["dead_ms"]
|
|
53
|
-
result
|
|
54
|
-
end
|
|
55
|
-
|
|
56
24
|
# Fetch the error history for this job.
|
|
57
25
|
#
|
|
58
26
|
# @rbs order: Zizq::sort_direction?
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Copyright (c) 2026 Chris Corbyn <chris@zizq.io>
|
|
2
|
+
# Licensed under the MIT License. See LICENSE file for details.
|
|
3
|
+
|
|
4
|
+
# rbs_inline: enabled
|
|
5
|
+
# frozen_string_literal: true
|
|
6
|
+
|
|
7
|
+
module Zizq
|
|
8
|
+
module Resources
|
|
9
|
+
# Typed wrapper around a job template — the fields shared between
|
|
10
|
+
# live jobs and cron entry job definitions.
|
|
11
|
+
class JobTemplate < Resource
|
|
12
|
+
def type = @data["type"] #: () -> String
|
|
13
|
+
def queue = @data["queue"] #: () -> String
|
|
14
|
+
def priority = @data["priority"] #: () -> Integer?
|
|
15
|
+
def payload = @data["payload"] #: () -> Hash[String, untyped]?
|
|
16
|
+
def retry_limit = @data["retry_limit"] #: () -> Integer?
|
|
17
|
+
def unique_key = @data["unique_key"] #: () -> String?
|
|
18
|
+
def unique_while = @data["unique_while"]&.to_sym #: () -> Zizq::unique_scope?
|
|
19
|
+
|
|
20
|
+
# Backoff configuration converted from the wire format (ms) to the
|
|
21
|
+
# Ruby-idiomatic format (seconds), matching the Zizq::backoff type.
|
|
22
|
+
def backoff #: () -> Zizq::backoff?
|
|
23
|
+
raw = @data["backoff"]
|
|
24
|
+
return nil unless raw
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
exponent: raw["exponent"].to_f,
|
|
28
|
+
base: raw["base_ms"] / 1000.0,
|
|
29
|
+
jitter: raw["jitter_ms"] / 1000.0
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Retention configuration converted from the wire format (ms) to the
|
|
34
|
+
# Ruby-idiomatic format (seconds), matching the Zizq::retention type.
|
|
35
|
+
def retention #: () -> Zizq::retention?
|
|
36
|
+
raw = @data["retention"]
|
|
37
|
+
return nil unless raw
|
|
38
|
+
|
|
39
|
+
result = {} #: Hash[Symbol, Float]
|
|
40
|
+
result[:completed] = raw["completed_ms"] / 1000.0 if raw["completed_ms"]
|
|
41
|
+
result[:dead] = raw["dead_ms"] / 1000.0 if raw["dead_ms"]
|
|
42
|
+
result
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/zizq/resources.rb
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
module Zizq
|
|
7
7
|
module Resources
|
|
8
8
|
autoload :Resource, "zizq/resources/resource"
|
|
9
|
+
autoload :JobTemplate, "zizq/resources/job_template"
|
|
9
10
|
autoload :Job, "zizq/resources/job"
|
|
10
11
|
autoload :ErrorRecord, "zizq/resources/error_record"
|
|
11
12
|
autoload :Page, "zizq/resources/page"
|
|
12
13
|
autoload :JobPage, "zizq/resources/job_page"
|
|
13
14
|
autoload :ErrorPage, "zizq/resources/error_page"
|
|
14
15
|
autoload :ErrorEnumerator, "zizq/resources/error_enumerator"
|
|
16
|
+
autoload :CronGroup, "zizq/resources/cron_group"
|
|
17
|
+
autoload :CronEntry, "zizq/resources/cron_entry"
|
|
15
18
|
end
|
|
16
19
|
end
|
data/lib/zizq/version.rb
CHANGED
data/lib/zizq.rb
CHANGED
|
@@ -12,20 +12,24 @@ require_relative "zizq/configuration"
|
|
|
12
12
|
autoload :MessagePack, "msgpack"
|
|
13
13
|
|
|
14
14
|
module Zizq
|
|
15
|
-
autoload :AckProcessor,
|
|
16
|
-
autoload :ActiveJobConfig,
|
|
17
|
-
autoload :Backoff,
|
|
18
|
-
autoload :BulkEnqueue,
|
|
19
|
-
autoload :Client,
|
|
20
|
-
autoload :
|
|
21
|
-
autoload :
|
|
22
|
-
autoload :
|
|
23
|
-
autoload :
|
|
24
|
-
autoload :
|
|
25
|
-
autoload :
|
|
26
|
-
autoload :
|
|
27
|
-
autoload :
|
|
28
|
-
autoload :
|
|
15
|
+
autoload :AckProcessor, "zizq/ack_processor"
|
|
16
|
+
autoload :ActiveJobConfig, "zizq/active_job_config"
|
|
17
|
+
autoload :Backoff, "zizq/backoff"
|
|
18
|
+
autoload :BulkEnqueue, "zizq/bulk_enqueue"
|
|
19
|
+
autoload :Client, "zizq/client"
|
|
20
|
+
autoload :Crontab, "zizq/crontab"
|
|
21
|
+
autoload :CrontabBuilder, "zizq/crontab_builder"
|
|
22
|
+
autoload :CrontabEntry, "zizq/crontab_entry"
|
|
23
|
+
autoload :CrontabEntryBuilder, "zizq/crontab_entry_builder"
|
|
24
|
+
autoload :EnqueueRequest, "zizq/enqueue_request"
|
|
25
|
+
autoload :EnqueueWith, "zizq/enqueue_with"
|
|
26
|
+
autoload :Job, "zizq/job"
|
|
27
|
+
autoload :JobConfig, "zizq/job_config"
|
|
28
|
+
autoload :Middleware, "zizq/middleware"
|
|
29
|
+
autoload :Lifecycle, "zizq/lifecycle"
|
|
30
|
+
autoload :Query, "zizq/query"
|
|
31
|
+
autoload :Resources, "zizq/resources"
|
|
32
|
+
autoload :Worker, "zizq/worker"
|
|
29
33
|
|
|
30
34
|
# Sentinel indicating a field should not be included in the request.
|
|
31
35
|
# Used as the default for update parameters.
|
|
@@ -59,7 +63,9 @@ module Zizq
|
|
|
59
63
|
def configure #: () { (Configuration) -> void } -> void
|
|
60
64
|
yield configuration
|
|
61
65
|
ensure
|
|
62
|
-
|
|
66
|
+
# shared client is potentially stale
|
|
67
|
+
@client&.close
|
|
68
|
+
@client = nil
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
# Returns a shared client instance built from the global configuration.
|
|
@@ -75,7 +81,9 @@ module Zizq
|
|
|
75
81
|
@client = Client.new(
|
|
76
82
|
url: configuration.url,
|
|
77
83
|
format: configuration.format,
|
|
78
|
-
ssl_context: configuration.ssl_context
|
|
84
|
+
ssl_context: configuration.ssl_context,
|
|
85
|
+
read_timeout: configuration.read_timeout,
|
|
86
|
+
stream_idle_timeout: configuration.stream_idle_timeout
|
|
79
87
|
)
|
|
80
88
|
end
|
|
81
89
|
end
|
|
@@ -114,6 +122,88 @@ module Zizq
|
|
|
114
122
|
Query.new(...)
|
|
115
123
|
end
|
|
116
124
|
|
|
125
|
+
# Return a list of all available Crontab schedules.
|
|
126
|
+
def crontabs #: () -> Array[String]
|
|
127
|
+
Zizq.client.list_cron_groups
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Define (or redefine) a Crontab schedule.
|
|
131
|
+
#
|
|
132
|
+
# This requires a Pro license on the Zizq server.
|
|
133
|
+
#
|
|
134
|
+
# Crontabs are used to define collections of recurring jobs that run on a
|
|
135
|
+
# specified schedule, such as at 2am on every Monday. Each entry on the
|
|
136
|
+
# Crontab is a single job enqueue, which the Zizq server automatically
|
|
137
|
+
# triggers at the correct point in time. Zizq uses standard Cron expression
|
|
138
|
+
# syntax (with support for seconds via 6-fields) to define entries.
|
|
139
|
+
#
|
|
140
|
+
# This is designed to be idempotent. You can define a schedule somewhere in
|
|
141
|
+
# your application startup process (after `Zizq.configure`) and it doesn't
|
|
142
|
+
# matter if multiple process all define the same schedule. Zizq is smart
|
|
143
|
+
# enough to handle this correctly.
|
|
144
|
+
#
|
|
145
|
+
# Entire schedules, and individual entries on a schedule, can be paused and
|
|
146
|
+
# resumed.
|
|
147
|
+
#
|
|
148
|
+
# By default schedules operate in the system time zone of the Zizq server
|
|
149
|
+
# but an explicit IANA timezone name can be specified when defining the
|
|
150
|
+
# Crontab.
|
|
151
|
+
#
|
|
152
|
+
# This method sends exactly *one* request to the Zizq server upon
|
|
153
|
+
# completion of the block. Any existing entries are retained. Any new
|
|
154
|
+
# entries are added, any absent entries are removed, and any modified
|
|
155
|
+
# entries are replaced. In short, whatever the block defines is what the
|
|
156
|
+
# entire resulting Crontab schedule will look like.
|
|
157
|
+
#
|
|
158
|
+
# Zizq.define_crontab("example", timezone: "Europe/Rome") do |cron|
|
|
159
|
+
# cron.define_entry(
|
|
160
|
+
# "refresh_data_warehose",
|
|
161
|
+
# "*/15 * * * *"
|
|
162
|
+
# ).enqueue(RefreshDataWarehoseJob, incremental: true)
|
|
163
|
+
#
|
|
164
|
+
# cron.define_entry(
|
|
165
|
+
# "expire_acess_tokens",
|
|
166
|
+
# "*/10 * * * * *"
|
|
167
|
+
# ).enqueue_raw(
|
|
168
|
+
# queue: "identity-server",
|
|
169
|
+
# type: "expire_access_tokens",
|
|
170
|
+
# priority: 100,
|
|
171
|
+
# payload: {},
|
|
172
|
+
# )
|
|
173
|
+
# end
|
|
174
|
+
#
|
|
175
|
+
# When jobs are pushed to the queue at their execution time, Zizq handles
|
|
176
|
+
# this atomically, so there is no risk of a duplicate enqueue for the same
|
|
177
|
+
# schedule tick. However, if you have long-running jobs that should not be
|
|
178
|
+
# permitted to overlap, such as in the case your schedule runs every 10
|
|
179
|
+
# seconds but jobs can take 30 seconds to execute, you should consider
|
|
180
|
+
# using unique jobs.
|
|
181
|
+
#
|
|
182
|
+
# @rbs name: String
|
|
183
|
+
# @rbs timezone: String?
|
|
184
|
+
# @rbs paused: bool?
|
|
185
|
+
# @rbs &block: (Zizq::CrontabBuilder) -> void
|
|
186
|
+
# @rbs return: Zizq::Crontab
|
|
187
|
+
def define_crontab(name, timezone: nil, paused: nil, &block)
|
|
188
|
+
crontab = Crontab.new(name)
|
|
189
|
+
crontab.redefine(timezone:, paused:, &block)
|
|
190
|
+
crontab
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Obtain a handle for the given Crontab schedule.
|
|
194
|
+
#
|
|
195
|
+
# This is a lazy operation. The schedule data is only fetched from the Zizq
|
|
196
|
+
# server upon first accessing data within the schedule.
|
|
197
|
+
#
|
|
198
|
+
# Zizq.crontab("default").paused?
|
|
199
|
+
# Zizq.crontab("default").resume!
|
|
200
|
+
#
|
|
201
|
+
# @rbs name: String
|
|
202
|
+
# @rbs return: Zizq::Crontab
|
|
203
|
+
def crontab(name)
|
|
204
|
+
Crontab.new(name)
|
|
205
|
+
end
|
|
206
|
+
|
|
117
207
|
# Enqueue a job by class with positional and keyword arguments.
|
|
118
208
|
#
|
|
119
209
|
# By default all arguments are serialized as JSON, which means hashes with
|
|
@@ -149,7 +239,7 @@ module Zizq
|
|
|
149
239
|
# end
|
|
150
240
|
# end
|
|
151
241
|
#
|
|
152
|
-
# @rbs job_class: Class & Zizq::
|
|
242
|
+
# @rbs job_class: Class & Zizq::JobConfig
|
|
153
243
|
# @rbs args: Array[untyped]
|
|
154
244
|
# @rbs kwargs: Hash[Symbol, untyped]
|
|
155
245
|
# @rbs &block: ?(EnqueueRequest) -> void
|
|
@@ -247,7 +337,7 @@ module Zizq
|
|
|
247
337
|
# @api private
|
|
248
338
|
# Build an EnqueueRequest for a single job class enqueue.
|
|
249
339
|
#
|
|
250
|
-
# @rbs job_class: Class & Zizq::
|
|
340
|
+
# @rbs job_class: Class & Zizq::JobConfig
|
|
251
341
|
# @rbs args: Array[untyped]
|
|
252
342
|
# @rbs kwargs: Hash[Symbol, untyped]
|
|
253
343
|
# @rbs &block: ?(EnqueueRequest) -> void
|
|
@@ -257,7 +347,7 @@ module Zizq
|
|
|
257
347
|
raise ArgumentError, "#{job_class.inspect} must include Zizq::Job or extend Zizq::ActiveJobConfig"
|
|
258
348
|
end
|
|
259
349
|
|
|
260
|
-
zizq_job_class = job_class #: Zizq::
|
|
350
|
+
zizq_job_class = job_class #: Zizq::JobConfig
|
|
261
351
|
req = zizq_job_class.zizq_enqueue_request(*args, **kwargs)
|
|
262
352
|
yield req if block_given?
|
|
263
353
|
req
|
|
@@ -16,12 +16,12 @@ module Zizq
|
|
|
16
16
|
# Collect a job class enqueue. Accepts the same arguments as
|
|
17
17
|
# `Zizq.enqueue`.
|
|
18
18
|
#
|
|
19
|
-
# @rbs job_class: Class & Zizq::
|
|
19
|
+
# @rbs job_class: Class & Zizq::JobConfig
|
|
20
20
|
# @rbs args: Array[untyped]
|
|
21
21
|
# @rbs kwargs: Hash[Symbol, untyped]
|
|
22
22
|
# @rbs &block: ?(EnqueueRequest) -> void
|
|
23
23
|
# @rbs return: void
|
|
24
|
-
def enqueue: (Class & Zizq::
|
|
24
|
+
def enqueue: (Class & Zizq::JobConfig job_class, *untyped args, **untyped kwargs) ?{ (EnqueueRequest) -> void } -> void
|
|
25
25
|
|
|
26
26
|
# Collect a raw enqueue. Accepts the same arguments as
|
|
27
27
|
# `Zizq.enqueue_raw`.
|
|
@@ -42,11 +42,19 @@ module Zizq
|
|
|
42
42
|
# Initialize a new instance of the client with the given base URL and
|
|
43
43
|
# optional format options.
|
|
44
44
|
#
|
|
45
|
+
# `read_timeout` and `stream_idle_timeout` are per-operation socket
|
|
46
|
+
# I/O timeouts (seconds). Each individual socket read/write is
|
|
47
|
+
# bounded by the timeout. The streaming `#take_jobs` endpoint uses
|
|
48
|
+
# `stream_idle_timeout` because the server sends heartbeats at
|
|
49
|
+
# periodic intervals which keeps the connection alive.
|
|
50
|
+
#
|
|
45
51
|
# @rbs url: String
|
|
46
52
|
# @rbs format: Zizq::format
|
|
47
53
|
# @rbs ssl_context: OpenSSL::SSL::SSLContext?
|
|
54
|
+
# @rbs read_timeout: Numeric
|
|
55
|
+
# @rbs stream_idle_timeout: Numeric
|
|
48
56
|
# @rbs return: void
|
|
49
|
-
def initialize: (url: String, ?format: Zizq::format, ?ssl_context: OpenSSL::SSL::SSLContext?) -> void
|
|
57
|
+
def initialize: (url: String, ?format: Zizq::format, ?ssl_context: OpenSSL::SSL::SSLContext?, ?read_timeout: Numeric, ?stream_idle_timeout: Numeric) -> void
|
|
50
58
|
|
|
51
59
|
# Close all thread-local HTTP clients and release connections.
|
|
52
60
|
def close: () -> untyped
|
|
@@ -196,6 +204,90 @@ module Zizq
|
|
|
196
204
|
# List all distinct queue names on the server.
|
|
197
205
|
def get_queues: () -> untyped
|
|
198
206
|
|
|
207
|
+
# List all cron group names.
|
|
208
|
+
#
|
|
209
|
+
# @rbs return: Array[String]
|
|
210
|
+
def list_cron_groups: () -> Array[String]
|
|
211
|
+
|
|
212
|
+
# Fetch a cron group and all its entries.
|
|
213
|
+
#
|
|
214
|
+
# @rbs name: String
|
|
215
|
+
# @rbs return: Resources::CronGroup
|
|
216
|
+
def get_cron_group: (String name) -> Resources::CronGroup
|
|
217
|
+
|
|
218
|
+
# Create or replace an entire cron group.
|
|
219
|
+
#
|
|
220
|
+
# Entries not present in the request are removed. Entries with unchanged
|
|
221
|
+
# expressions preserve their scheduling state.
|
|
222
|
+
#
|
|
223
|
+
# @rbs name: String
|
|
224
|
+
# @rbs paused: bool?
|
|
225
|
+
# @rbs entries: Array[Zizq::cron_entry_params]
|
|
226
|
+
# @rbs return: Resources::CronGroup
|
|
227
|
+
def replace_cron_group: (String name, ?paused: bool?, ?entries: Array[Zizq::cron_entry_params]) -> Resources::CronGroup
|
|
228
|
+
|
|
229
|
+
# Update group-level fields (currently just pause/unpause).
|
|
230
|
+
#
|
|
231
|
+
# @rbs name: String
|
|
232
|
+
# @rbs paused: bool?
|
|
233
|
+
# @rbs return: Resources::CronGroup
|
|
234
|
+
def update_cron_group: (String name, ?paused: bool?) -> Resources::CronGroup
|
|
235
|
+
|
|
236
|
+
# Delete a cron group and all its entries.
|
|
237
|
+
#
|
|
238
|
+
# @rbs name: String
|
|
239
|
+
# @rbs return: void
|
|
240
|
+
def delete_cron_group: (String name) -> void
|
|
241
|
+
|
|
242
|
+
# Fetch a single cron entry.
|
|
243
|
+
#
|
|
244
|
+
# @rbs group: String
|
|
245
|
+
# @rbs entry: String
|
|
246
|
+
# @rbs return: Resources::CronEntry
|
|
247
|
+
def get_cron_group_entry: (String group, String entry) -> Resources::CronEntry
|
|
248
|
+
|
|
249
|
+
# Add a single entry to a cron group (creates the group if needed).
|
|
250
|
+
#
|
|
251
|
+
# Raises a ClientError (409 Conflict) if an entry with the same name
|
|
252
|
+
# already exists.
|
|
253
|
+
#
|
|
254
|
+
# @rbs group: String
|
|
255
|
+
# @rbs name: String
|
|
256
|
+
# @rbs expression: String
|
|
257
|
+
# @rbs job: Zizq::cron_job_params
|
|
258
|
+
# @rbs timezone: String?
|
|
259
|
+
# @rbs paused: bool?
|
|
260
|
+
# @rbs return: Resources::CronEntry
|
|
261
|
+
def add_cron_group_entry: (String group, name: String, expression: String, job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Resources::CronEntry
|
|
262
|
+
|
|
263
|
+
# Create or replace a single cron entry.
|
|
264
|
+
#
|
|
265
|
+
# Preserves scheduling state if the expression is unchanged.
|
|
266
|
+
#
|
|
267
|
+
# @rbs group: String
|
|
268
|
+
# @rbs entry: String
|
|
269
|
+
# @rbs expression: String
|
|
270
|
+
# @rbs job: Zizq::cron_job_params
|
|
271
|
+
# @rbs timezone: String?
|
|
272
|
+
# @rbs paused: bool?
|
|
273
|
+
# @rbs return: Resources::CronEntry
|
|
274
|
+
def replace_cron_group_entry: (String group, String entry, expression: String, job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Resources::CronEntry
|
|
275
|
+
|
|
276
|
+
# Update entry-level fields (currently just pause/unpause).
|
|
277
|
+
#
|
|
278
|
+
# @rbs group: String
|
|
279
|
+
# @rbs entry: String
|
|
280
|
+
# @rbs paused: bool
|
|
281
|
+
# @rbs return: Resources::CronEntry
|
|
282
|
+
def update_cron_group_entry: (String group, String entry, paused: bool) -> Resources::CronEntry
|
|
283
|
+
|
|
284
|
+
# Delete a single cron entry.
|
|
285
|
+
#
|
|
286
|
+
# @rbs group: String
|
|
287
|
+
# @rbs entry: String
|
|
288
|
+
# @rbs return: void
|
|
289
|
+
def delete_cron_group_entry: (String group, String entry) -> void
|
|
290
|
+
|
|
199
291
|
# Mark a job as successfully completed (ack).
|
|
200
292
|
#
|
|
201
293
|
# If this method (or [`#report_failure`]) is not called upon job
|
|
@@ -330,9 +422,38 @@ module Zizq
|
|
|
330
422
|
|
|
331
423
|
private
|
|
332
424
|
|
|
425
|
+
# URL-encode a single path segment.
|
|
426
|
+
def enc: (untyped value) -> untyped
|
|
427
|
+
|
|
333
428
|
# Build a relative path with optional query parameters.
|
|
334
429
|
def build_path: (untyped path, ?params: untyped) -> untyped
|
|
335
430
|
|
|
431
|
+
# Validate and build a cron entry body from keyword arguments.
|
|
432
|
+
#
|
|
433
|
+
# @rbs name: String
|
|
434
|
+
# @rbs expression: String
|
|
435
|
+
# @rbs job: Zizq::cron_job_params
|
|
436
|
+
# @rbs timezone: String?
|
|
437
|
+
# @rbs paused: bool?
|
|
438
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
439
|
+
def build_cron_entry: (?name: String, ?expression: String, ?job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Hash[Symbol, untyped]
|
|
440
|
+
|
|
441
|
+
# Validate and build a cron job template from keyword arguments.
|
|
442
|
+
#
|
|
443
|
+
# Uses keyword args so that unknown keys raise ArgumentError.
|
|
444
|
+
#
|
|
445
|
+
# @rbs type: String
|
|
446
|
+
# @rbs queue: String
|
|
447
|
+
# @rbs payload: untyped
|
|
448
|
+
# @rbs priority: Integer?
|
|
449
|
+
# @rbs retry_limit: Integer?
|
|
450
|
+
# @rbs backoff: Zizq::backoff?
|
|
451
|
+
# @rbs retention: Zizq::retention?
|
|
452
|
+
# @rbs unique_key: String?
|
|
453
|
+
# @rbs unique_while: Zizq::unique_scope?
|
|
454
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
455
|
+
def build_cron_job: (?type: String, ?queue: String, ?payload: untyped, ?priority: Integer?, ?retry_limit: Integer?, ?backoff: Zizq::backoff?, ?retention: Zizq::retention?, ?unique_key: String?, ?unique_while: Zizq::unique_scope?) -> Hash[Symbol, untyped]
|
|
456
|
+
|
|
336
457
|
# Validate and normalize filter parameters for bulk operations.
|
|
337
458
|
#
|
|
338
459
|
# Uses keyword arguments so that unknown keys raise ArgumentError.
|
|
@@ -419,6 +540,8 @@ module Zizq
|
|
|
419
540
|
|
|
420
541
|
def raw_post: (untyped path) -> untyped
|
|
421
542
|
|
|
543
|
+
def put: (untyped path, untyped body) -> untyped
|
|
544
|
+
|
|
422
545
|
def delete: (untyped path, ?params: untyped) -> untyped
|
|
423
546
|
|
|
424
547
|
def patch: (untyped path, untyped body, ?params: untyped) -> untyped
|
|
@@ -35,6 +35,27 @@ module Zizq
|
|
|
35
35
|
# Note: Mutual TLS support requires a Zizq Pro license on the server.
|
|
36
36
|
attr_accessor tls: Zizq::tls_options?
|
|
37
37
|
|
|
38
|
+
# Per-operation socket I/O timeout (seconds) for regular API calls
|
|
39
|
+
# (enqueue, queries, mutations). Each socket read/write is bounded
|
|
40
|
+
# by this value. A request whose handshake or any single read exceeds
|
|
41
|
+
# this raises `IO::TimeoutError`.
|
|
42
|
+
#
|
|
43
|
+
# Default: 30.
|
|
44
|
+
attr_accessor read_timeout: Numeric
|
|
45
|
+
|
|
46
|
+
# Per-operation socket I/O timeout (seconds) for the long-lived
|
|
47
|
+
# `#take_jobs` stream. The server sends heartbeats every ~3 seconds,
|
|
48
|
+
# so each read returns within that window and keeps the connection
|
|
49
|
+
# alive; the connection only times out if the server falls silent for
|
|
50
|
+
# longer than this. The Worker catches the resulting error and
|
|
51
|
+
# reconnects with backoff.
|
|
52
|
+
#
|
|
53
|
+
# Should be comfortably above the server's heartbeat interval to
|
|
54
|
+
# avoid false-positive disconnects.
|
|
55
|
+
#
|
|
56
|
+
# Default: 30.
|
|
57
|
+
attr_accessor stream_idle_timeout: Numeric
|
|
58
|
+
|
|
38
59
|
# Middleware chain for enqueue. Each middleware receives an
|
|
39
60
|
# `EnqueueRequest` and a chain to continue.
|
|
40
61
|
attr_reader enqueue_middleware: Middleware::Chain[EnqueueRequest, EnqueueRequest]
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Generated from lib/zizq/crontab.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Zizq
|
|
4
|
+
# Represents a Crontab schedule defined on the Zizq server.
|
|
5
|
+
#
|
|
6
|
+
# This requires a Pro license on the Zizq server.
|
|
7
|
+
#
|
|
8
|
+
# The actual data is lazily fetched when first accessed.
|
|
9
|
+
#
|
|
10
|
+
# Crontabs are used to define collections of recurring jobs that run on a
|
|
11
|
+
# specified schedule, such as at 2am on every Monday. Each entry on the
|
|
12
|
+
# Crontab is a single job enqueue, which the Zizq server automatically
|
|
13
|
+
# triggers at the correct point in time. Zizq uses standard Cron expression
|
|
14
|
+
# syntax (with support for seconds via 6-fields) to define entries.
|
|
15
|
+
#
|
|
16
|
+
# Entire schedules, and individual entries on a schedule, can be paused and
|
|
17
|
+
# resumed.
|
|
18
|
+
#
|
|
19
|
+
# By default schedules operate in the system time zone of the Zizq server
|
|
20
|
+
# but an explicit IANA timezone name can be specified when defining the
|
|
21
|
+
# Crontab.
|
|
22
|
+
class Crontab
|
|
23
|
+
# The name of the cron group that this schedule is backed by.
|
|
24
|
+
attr_reader name: String
|
|
25
|
+
|
|
26
|
+
# True if this schedule is paused.
|
|
27
|
+
#
|
|
28
|
+
# When paused, the scheduler continues to run but does not enqueue any jobs
|
|
29
|
+
# and only advances the timer.
|
|
30
|
+
attr_writer paused: bool?
|
|
31
|
+
|
|
32
|
+
# Initialize the Crontab with the given group name.
|
|
33
|
+
#
|
|
34
|
+
# @rbs name: String
|
|
35
|
+
def initialize: (String name) -> untyped
|
|
36
|
+
|
|
37
|
+
# Fetch data from the Zizq server if not already fetched.
|
|
38
|
+
#
|
|
39
|
+
# Once fetched, this method becomes a no-op, unless #clear is called to
|
|
40
|
+
# remove the fetched data.
|
|
41
|
+
def materialize: () -> untyped
|
|
42
|
+
|
|
43
|
+
# Clear materialized data that was fetched from the Zizq server.
|
|
44
|
+
#
|
|
45
|
+
# This triggers a refetch when the data is next accessed.
|
|
46
|
+
def clear: () -> untyped
|
|
47
|
+
|
|
48
|
+
# Delete this entire Crontab schedule and its entries.
|
|
49
|
+
def delete!: () -> untyped
|
|
50
|
+
|
|
51
|
+
# Pause this entire Crontab schedule.
|
|
52
|
+
#
|
|
53
|
+
# All entries will stop enqueueing jobs, but the server continues to
|
|
54
|
+
# advance the schedule until it is resumed.
|
|
55
|
+
def pause!: () -> untyped
|
|
56
|
+
|
|
57
|
+
# Resume this Crontab schedule if it is currently paused.
|
|
58
|
+
#
|
|
59
|
+
# Individual entries that are paused will remain paused.
|
|
60
|
+
def resume!: () -> untyped
|
|
61
|
+
|
|
62
|
+
# Check if this schedule is currently paused.
|
|
63
|
+
def paused: () -> untyped
|
|
64
|
+
|
|
65
|
+
# Check if this schedule is currently paused.
|
|
66
|
+
#
|
|
67
|
+
# Alias of #paused.
|
|
68
|
+
def paused?: () -> untyped
|
|
69
|
+
|
|
70
|
+
# Return the timestamp at which this Crontab schedule was last paused.
|
|
71
|
+
def paused_at: () -> untyped
|
|
72
|
+
|
|
73
|
+
# Return the timestamp at which this Crontab schedule was last resumed.
|
|
74
|
+
def resumed_at: () -> untyped
|
|
75
|
+
|
|
76
|
+
# Return a Hash of Zizq::CrontabEntry instances keyed by their names.
|
|
77
|
+
#
|
|
78
|
+
# Each entry specifies the cron expression at which it executes,
|
|
79
|
+
# information about when it last/next enqueued a job, and details of the
|
|
80
|
+
# job that the entry enqueues.
|
|
81
|
+
def entries: () -> untyped
|
|
82
|
+
|
|
83
|
+
# Redefine (replace) this Crontab schedule with another.
|
|
84
|
+
#
|
|
85
|
+
# This is equivalent to calling `Zizq.define_crontab` and is idempotent
|
|
86
|
+
# when given the same schedule more than once.
|
|
87
|
+
#
|
|
88
|
+
# @rbs ?timezone: String?
|
|
89
|
+
# @rbs ?paused: bool?
|
|
90
|
+
# @rbs &block: (Zizq::CrontabBuilder) -> void
|
|
91
|
+
# @rbs return: self
|
|
92
|
+
def redefine: (?timezone: untyped, ?paused: untyped) { (Zizq::CrontabBuilder) -> void } -> self
|
|
93
|
+
|
|
94
|
+
# Return a handle for the specified Zizq::CrontabEntry.
|
|
95
|
+
#
|
|
96
|
+
# The entry can be paused or resumed is isolation, can be deleted entirely
|
|
97
|
+
# or can be redefined (replaced) with another entry.
|
|
98
|
+
#
|
|
99
|
+
# @rbs name: String
|
|
100
|
+
# @rbs return: Zizq::CrontabEntry
|
|
101
|
+
def entry: (String name) -> Zizq::CrontabEntry
|
|
102
|
+
|
|
103
|
+
# Define (or redefine) an entry with this Crontab schedule.
|
|
104
|
+
#
|
|
105
|
+
# Defining the same entry more than once is idempotent. If the entry does
|
|
106
|
+
# not exist, it is added to the schedule. If the entry already exists, it
|
|
107
|
+
# replaces the current entry.
|
|
108
|
+
#
|
|
109
|
+
# The return value is a Zizq::CrontabEntryBuilder instance, on which the
|
|
110
|
+
# caller must call one of the enqueue methods (`enqueue`, `enqueue_raw`,
|
|
111
|
+
# optionally chained onto `enqueue_with`, exactly the same as a regular job
|
|
112
|
+
# enqueue).
|
|
113
|
+
#
|
|
114
|
+
# All enqueue options are supported *except* `delay` and `ready_at` which
|
|
115
|
+
# make no sense for recurring jobs.
|
|
116
|
+
#
|
|
117
|
+
# Bulk enqueues are not supported.
|
|
118
|
+
#
|
|
119
|
+
# crontab.define_entry(
|
|
120
|
+
# "refresh_data_warehose",
|
|
121
|
+
# "*/15 * * * *",
|
|
122
|
+
# ).enqueue(RefreshDataWarehoseJob, incremental: true)
|
|
123
|
+
#
|
|
124
|
+
# @rbs name: String
|
|
125
|
+
# @rbs expression: String
|
|
126
|
+
# @rbs timezone: String?
|
|
127
|
+
# @rbs paused: bool?
|
|
128
|
+
# @rbs return: Zizq::CrontabEntryBuilder
|
|
129
|
+
def define_entry: (String name, String expression, ?timezone: String?, ?paused: bool?) -> Zizq::CrontabEntryBuilder
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
# @rbs result: Zizq::Resources::CronGroup
|
|
134
|
+
# @rbs return: self
|
|
135
|
+
def materialize_with: (Zizq::Resources::CronGroup result) -> self
|
|
136
|
+
|
|
137
|
+
# @rbs result: Zizq::Resources::CronEntry
|
|
138
|
+
# @rbs return: Zizq::CrontabEntry
|
|
139
|
+
def materialize_entry_with: (Zizq::Resources::CronEntry result) -> Zizq::CrontabEntry
|
|
140
|
+
end
|
|
141
|
+
end
|