zizq 0.2.0 → 0.3.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 +4 -4
- data/README.md +19 -0
- data/lib/zizq/active_job_config.rb +39 -18
- data/lib/zizq/bulk_enqueue.rb +1 -1
- data/lib/zizq/client.rb +205 -7
- 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 +108 -20
- data/sig/generated/zizq/active_job_config.rbs +19 -8
- data/sig/generated/zizq/bulk_enqueue.rbs +2 -2
- data/sig/generated/zizq/client.rbs +115 -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 +20 -6
|
@@ -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.
|
|
@@ -114,6 +120,88 @@ module Zizq
|
|
|
114
120
|
Query.new(...)
|
|
115
121
|
end
|
|
116
122
|
|
|
123
|
+
# Return a list of all available Crontab schedules.
|
|
124
|
+
def crontabs #: () -> Array[String]
|
|
125
|
+
Zizq.client.list_cron_groups
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Define (or redefine) a Crontab schedule.
|
|
129
|
+
#
|
|
130
|
+
# This requires a Pro license on the Zizq server.
|
|
131
|
+
#
|
|
132
|
+
# Crontabs are used to define collections of recurring jobs that run on a
|
|
133
|
+
# specified schedule, such as at 2am on every Monday. Each entry on the
|
|
134
|
+
# Crontab is a single job enqueue, which the Zizq server automatically
|
|
135
|
+
# triggers at the correct point in time. Zizq uses standard Cron expression
|
|
136
|
+
# syntax (with support for seconds via 6-fields) to define entries.
|
|
137
|
+
#
|
|
138
|
+
# This is designed to be idempotent. You can define a schedule somewhere in
|
|
139
|
+
# your application startup process (after `Zizq.configure`) and it doesn't
|
|
140
|
+
# matter if multiple process all define the same schedule. Zizq is smart
|
|
141
|
+
# enough to handle this correctly.
|
|
142
|
+
#
|
|
143
|
+
# Entire schedules, and individual entries on a schedule, can be paused and
|
|
144
|
+
# resumed.
|
|
145
|
+
#
|
|
146
|
+
# By default schedules operate in the system time zone of the Zizq server
|
|
147
|
+
# but an explicit IANA timezone name can be specified when defining the
|
|
148
|
+
# Crontab.
|
|
149
|
+
#
|
|
150
|
+
# This method sends exactly *one* request to the Zizq server upon
|
|
151
|
+
# completion of the block. Any existing entries are retained. Any new
|
|
152
|
+
# entries are added, any absent entries are removed, and any modified
|
|
153
|
+
# entries are replaced. In short, whatever the block defines is what the
|
|
154
|
+
# entire resulting Crontab schedule will look like.
|
|
155
|
+
#
|
|
156
|
+
# Zizq.define_crontab("example", timezone: "Europe/Rome") do |cron|
|
|
157
|
+
# cron.define_entry(
|
|
158
|
+
# "refresh_data_warehose",
|
|
159
|
+
# "*/15 * * * *"
|
|
160
|
+
# ).enqueue(RefreshDataWarehoseJob, incremental: true)
|
|
161
|
+
#
|
|
162
|
+
# cron.define_entry(
|
|
163
|
+
# "expire_acess_tokens",
|
|
164
|
+
# "*/10 * * * * *"
|
|
165
|
+
# ).enqueue_raw(
|
|
166
|
+
# queue: "identity-server",
|
|
167
|
+
# type: "expire_access_tokens",
|
|
168
|
+
# priority: 100,
|
|
169
|
+
# payload: {},
|
|
170
|
+
# )
|
|
171
|
+
# end
|
|
172
|
+
#
|
|
173
|
+
# When jobs are pushed to the queue at their execution time, Zizq handles
|
|
174
|
+
# this atomically, so there is no risk of a duplicate enqueue for the same
|
|
175
|
+
# schedule tick. However, if you have long-running jobs that should not be
|
|
176
|
+
# permitted to overlap, such as in the case your schedule runs every 10
|
|
177
|
+
# seconds but jobs can take 30 seconds to execute, you should consider
|
|
178
|
+
# using unique jobs.
|
|
179
|
+
#
|
|
180
|
+
# @rbs name: String
|
|
181
|
+
# @rbs timezone: String?
|
|
182
|
+
# @rbs paused: bool?
|
|
183
|
+
# @rbs &block: (Zizq::CrontabBuilder) -> void
|
|
184
|
+
# @rbs return: Zizq::Crontab
|
|
185
|
+
def define_crontab(name, timezone: nil, paused: nil, &block)
|
|
186
|
+
crontab = Crontab.new(name)
|
|
187
|
+
crontab.redefine(timezone:, paused:, &block)
|
|
188
|
+
crontab
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Obtain a handle for the given Crontab schedule.
|
|
192
|
+
#
|
|
193
|
+
# This is a lazy operation. The schedule data is only fetched from the Zizq
|
|
194
|
+
# server upon first accessing data within the schedule.
|
|
195
|
+
#
|
|
196
|
+
# Zizq.crontab("default").paused?
|
|
197
|
+
# Zizq.crontab("default").resume!
|
|
198
|
+
#
|
|
199
|
+
# @rbs name: String
|
|
200
|
+
# @rbs return: Zizq::Crontab
|
|
201
|
+
def crontab(name)
|
|
202
|
+
Crontab.new(name)
|
|
203
|
+
end
|
|
204
|
+
|
|
117
205
|
# Enqueue a job by class with positional and keyword arguments.
|
|
118
206
|
#
|
|
119
207
|
# By default all arguments are serialized as JSON, which means hashes with
|
|
@@ -149,7 +237,7 @@ module Zizq
|
|
|
149
237
|
# end
|
|
150
238
|
# end
|
|
151
239
|
#
|
|
152
|
-
# @rbs job_class: Class & Zizq::
|
|
240
|
+
# @rbs job_class: Class & Zizq::JobConfig
|
|
153
241
|
# @rbs args: Array[untyped]
|
|
154
242
|
# @rbs kwargs: Hash[Symbol, untyped]
|
|
155
243
|
# @rbs &block: ?(EnqueueRequest) -> void
|
|
@@ -247,17 +335,17 @@ module Zizq
|
|
|
247
335
|
# @api private
|
|
248
336
|
# Build an EnqueueRequest for a single job class enqueue.
|
|
249
337
|
#
|
|
250
|
-
# @rbs job_class: Class & Zizq::
|
|
338
|
+
# @rbs job_class: Class & Zizq::JobConfig
|
|
251
339
|
# @rbs args: Array[untyped]
|
|
252
340
|
# @rbs kwargs: Hash[Symbol, untyped]
|
|
253
341
|
# @rbs &block: ?(EnqueueRequest) -> void
|
|
254
342
|
# @rbs return: EnqueueRequest
|
|
255
343
|
def build_enqueue_request(job_class, *args, **kwargs, &block)
|
|
256
|
-
unless job_class.is_a?(Class) && job_class
|
|
257
|
-
raise ArgumentError, "#{job_class.inspect} must include Zizq::Job"
|
|
344
|
+
unless job_class.is_a?(Class) && job_class.is_a?(Zizq::JobConfig)
|
|
345
|
+
raise ArgumentError, "#{job_class.inspect} must include Zizq::Job or extend Zizq::ActiveJobConfig"
|
|
258
346
|
end
|
|
259
347
|
|
|
260
|
-
zizq_job_class = job_class #: Zizq::
|
|
348
|
+
zizq_job_class = job_class #: Zizq::JobConfig
|
|
261
349
|
req = zizq_job_class.zizq_enqueue_request(*args, **kwargs)
|
|
262
350
|
yield req if block_given?
|
|
263
351
|
req
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
module Zizq
|
|
4
4
|
# Zizq configuration DSL for ActiveJob classes.
|
|
5
5
|
#
|
|
6
|
-
# Extend this module in an ActiveJob subclass to
|
|
7
|
-
# features like unique jobs,
|
|
6
|
+
# Extend this module in an ActiveJob subclass to allow enqueueing jobs via
|
|
7
|
+
# `Zizq.enqueue` and to gain access to Zizq features like unique jobs,
|
|
8
|
+
# backoff, and retention:
|
|
8
9
|
#
|
|
9
10
|
# class SendEmailJob < ApplicationJob
|
|
10
11
|
# extend Zizq::ActiveJobConfig
|
|
@@ -30,20 +31,30 @@ module Zizq
|
|
|
30
31
|
# ActiveJob::Base.new — invisible to steep without this.
|
|
31
32
|
def new: (*untyped, **untyped) -> untyped
|
|
32
33
|
|
|
33
|
-
#
|
|
34
|
+
# ActiveJob::Base.queue_name — invisible to steep without this.
|
|
35
|
+
def queue_name: () -> String?
|
|
36
|
+
|
|
37
|
+
# Use ActiveJob's `queue_name` as the default queue, falling back to
|
|
38
|
+
# any explicit `zizq_queue` setting, then "default".
|
|
39
|
+
def zizq_queue: (?untyped name) -> untyped
|
|
40
|
+
|
|
41
|
+
# Serialize using ActiveJob's own format.
|
|
34
42
|
#
|
|
35
43
|
# Creates a temporary ActiveJob instance to produce the canonical
|
|
36
|
-
# serialized form
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# This is needed so that unique job keys can be correctly generated.
|
|
44
|
+
# serialized form. Returns the full serialized hash (including
|
|
45
|
+
# `job_class`, `arguments`, `queue_name`, etc.) so that the payload
|
|
46
|
+
# stored in Zizq matches what `ActiveJob::Base.execute` expects.
|
|
41
47
|
def zizq_serialize: (*untyped args, **untyped kwargs) -> untyped
|
|
42
48
|
|
|
43
49
|
# Deserialization is handled by ActiveJob::Base.execute on the worker
|
|
44
50
|
# side. This method is not used in the ActiveJob dispatch path.
|
|
45
51
|
def zizq_deserialize: (untyped _payload) -> untyped
|
|
46
52
|
|
|
53
|
+
# Override unique key generation to hash only the arguments portion
|
|
54
|
+
# of the serialized payload. The full payload contains volatile fields
|
|
55
|
+
# (job_id, enqueued_at, etc.) that change per instance.
|
|
56
|
+
def zizq_unique_key: (*untyped args, **untyped kwargs) -> untyped
|
|
57
|
+
|
|
47
58
|
# Generate a jq expression that exactly matches payloads with the given
|
|
48
59
|
# arguments.
|
|
49
60
|
#
|
|
@@ -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`.
|
|
@@ -196,6 +196,90 @@ module Zizq
|
|
|
196
196
|
# List all distinct queue names on the server.
|
|
197
197
|
def get_queues: () -> untyped
|
|
198
198
|
|
|
199
|
+
# List all cron group names.
|
|
200
|
+
#
|
|
201
|
+
# @rbs return: Array[String]
|
|
202
|
+
def list_cron_groups: () -> Array[String]
|
|
203
|
+
|
|
204
|
+
# Fetch a cron group and all its entries.
|
|
205
|
+
#
|
|
206
|
+
# @rbs name: String
|
|
207
|
+
# @rbs return: Resources::CronGroup
|
|
208
|
+
def get_cron_group: (String name) -> Resources::CronGroup
|
|
209
|
+
|
|
210
|
+
# Create or replace an entire cron group.
|
|
211
|
+
#
|
|
212
|
+
# Entries not present in the request are removed. Entries with unchanged
|
|
213
|
+
# expressions preserve their scheduling state.
|
|
214
|
+
#
|
|
215
|
+
# @rbs name: String
|
|
216
|
+
# @rbs paused: bool?
|
|
217
|
+
# @rbs entries: Array[Zizq::cron_entry_params]
|
|
218
|
+
# @rbs return: Resources::CronGroup
|
|
219
|
+
def replace_cron_group: (String name, ?paused: bool?, ?entries: Array[Zizq::cron_entry_params]) -> Resources::CronGroup
|
|
220
|
+
|
|
221
|
+
# Update group-level fields (currently just pause/unpause).
|
|
222
|
+
#
|
|
223
|
+
# @rbs name: String
|
|
224
|
+
# @rbs paused: bool?
|
|
225
|
+
# @rbs return: Resources::CronGroup
|
|
226
|
+
def update_cron_group: (String name, ?paused: bool?) -> Resources::CronGroup
|
|
227
|
+
|
|
228
|
+
# Delete a cron group and all its entries.
|
|
229
|
+
#
|
|
230
|
+
# @rbs name: String
|
|
231
|
+
# @rbs return: void
|
|
232
|
+
def delete_cron_group: (String name) -> void
|
|
233
|
+
|
|
234
|
+
# Fetch a single cron entry.
|
|
235
|
+
#
|
|
236
|
+
# @rbs group: String
|
|
237
|
+
# @rbs entry: String
|
|
238
|
+
# @rbs return: Resources::CronEntry
|
|
239
|
+
def get_cron_group_entry: (String group, String entry) -> Resources::CronEntry
|
|
240
|
+
|
|
241
|
+
# Add a single entry to a cron group (creates the group if needed).
|
|
242
|
+
#
|
|
243
|
+
# Raises a ClientError (409 Conflict) if an entry with the same name
|
|
244
|
+
# already exists.
|
|
245
|
+
#
|
|
246
|
+
# @rbs group: String
|
|
247
|
+
# @rbs name: String
|
|
248
|
+
# @rbs expression: String
|
|
249
|
+
# @rbs job: Zizq::cron_job_params
|
|
250
|
+
# @rbs timezone: String?
|
|
251
|
+
# @rbs paused: bool?
|
|
252
|
+
# @rbs return: Resources::CronEntry
|
|
253
|
+
def add_cron_group_entry: (String group, name: String, expression: String, job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Resources::CronEntry
|
|
254
|
+
|
|
255
|
+
# Create or replace a single cron entry.
|
|
256
|
+
#
|
|
257
|
+
# Preserves scheduling state if the expression is unchanged.
|
|
258
|
+
#
|
|
259
|
+
# @rbs group: String
|
|
260
|
+
# @rbs entry: String
|
|
261
|
+
# @rbs expression: String
|
|
262
|
+
# @rbs job: Zizq::cron_job_params
|
|
263
|
+
# @rbs timezone: String?
|
|
264
|
+
# @rbs paused: bool?
|
|
265
|
+
# @rbs return: Resources::CronEntry
|
|
266
|
+
def replace_cron_group_entry: (String group, String entry, expression: String, job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Resources::CronEntry
|
|
267
|
+
|
|
268
|
+
# Update entry-level fields (currently just pause/unpause).
|
|
269
|
+
#
|
|
270
|
+
# @rbs group: String
|
|
271
|
+
# @rbs entry: String
|
|
272
|
+
# @rbs paused: bool
|
|
273
|
+
# @rbs return: Resources::CronEntry
|
|
274
|
+
def update_cron_group_entry: (String group, String entry, paused: bool) -> Resources::CronEntry
|
|
275
|
+
|
|
276
|
+
# Delete a single cron entry.
|
|
277
|
+
#
|
|
278
|
+
# @rbs group: String
|
|
279
|
+
# @rbs entry: String
|
|
280
|
+
# @rbs return: void
|
|
281
|
+
def delete_cron_group_entry: (String group, String entry) -> void
|
|
282
|
+
|
|
199
283
|
# Mark a job as successfully completed (ack).
|
|
200
284
|
#
|
|
201
285
|
# If this method (or [`#report_failure`]) is not called upon job
|
|
@@ -330,9 +414,38 @@ module Zizq
|
|
|
330
414
|
|
|
331
415
|
private
|
|
332
416
|
|
|
417
|
+
# URL-encode a single path segment.
|
|
418
|
+
def enc: (untyped value) -> untyped
|
|
419
|
+
|
|
333
420
|
# Build a relative path with optional query parameters.
|
|
334
421
|
def build_path: (untyped path, ?params: untyped) -> untyped
|
|
335
422
|
|
|
423
|
+
# Validate and build a cron entry body from keyword arguments.
|
|
424
|
+
#
|
|
425
|
+
# @rbs name: String
|
|
426
|
+
# @rbs expression: String
|
|
427
|
+
# @rbs job: Zizq::cron_job_params
|
|
428
|
+
# @rbs timezone: String?
|
|
429
|
+
# @rbs paused: bool?
|
|
430
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
431
|
+
def build_cron_entry: (?name: String, ?expression: String, ?job: Zizq::cron_job_params, ?timezone: String?, ?paused: bool?) -> Hash[Symbol, untyped]
|
|
432
|
+
|
|
433
|
+
# Validate and build a cron job template from keyword arguments.
|
|
434
|
+
#
|
|
435
|
+
# Uses keyword args so that unknown keys raise ArgumentError.
|
|
436
|
+
#
|
|
437
|
+
# @rbs type: String
|
|
438
|
+
# @rbs queue: String
|
|
439
|
+
# @rbs payload: untyped
|
|
440
|
+
# @rbs priority: Integer?
|
|
441
|
+
# @rbs retry_limit: Integer?
|
|
442
|
+
# @rbs backoff: Zizq::backoff?
|
|
443
|
+
# @rbs retention: Zizq::retention?
|
|
444
|
+
# @rbs unique_key: String?
|
|
445
|
+
# @rbs unique_while: Zizq::unique_scope?
|
|
446
|
+
# @rbs return: Hash[Symbol, untyped]
|
|
447
|
+
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]
|
|
448
|
+
|
|
336
449
|
# Validate and normalize filter parameters for bulk operations.
|
|
337
450
|
#
|
|
338
451
|
# Uses keyword arguments so that unknown keys raise ArgumentError.
|
|
@@ -419,6 +532,8 @@ module Zizq
|
|
|
419
532
|
|
|
420
533
|
def raw_post: (untyped path) -> untyped
|
|
421
534
|
|
|
535
|
+
def put: (untyped path, untyped body) -> untyped
|
|
536
|
+
|
|
422
537
|
def delete: (untyped path, ?params: untyped) -> untyped
|
|
423
538
|
|
|
424
539
|
def patch: (untyped path, untyped body, ?params: untyped) -> untyped
|
|
@@ -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
|