robin 0.1.0-java → 0.1.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +14 -1
- data/lib/robin/cron.rb +180 -16
- data/lib/robin/periodic.rb +4 -3
- data/lib/robin/version.rb +1 -1
- data/lib/robin_resp/robin_resp.jar +0 -0
- data/sig/manifest.yaml +1 -0
- data/sig/robin/cron.rbs +69 -2
- data/sig/robin/periodic.rbs +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e413094ad653fc76b7f441fc8bb954919078c8eacadbf5f7c2cab9827b2d30c1
|
|
4
|
+
data.tar.gz: 10c7b450515c64a584e212f7110dc749d8d8dc13bb6648edb3f6e5db6a7613e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d553b958f81246f5b9e7bdac4a596196065a63456c49822b396872e188d2620a726469a07206762bcb2704ed93bda034c9ab8384f1ac37ef6d1b04637896310
|
|
7
|
+
data.tar.gz: 9bdca5856290b92d9520d6f6676d7f14287e897f53ef880d160f4dc2aa020e968136cbff60525b8e1637a160638748a69dc3ae0a3fd53a45793b4bcb6c086c43
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.1] - 2026-11-22
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Cron expressions take fugit's additions: days counted from the end of
|
|
15
|
+
the month (`-2`), the nth weekday of the month (`MON#2`, `FRI#L`) and
|
|
16
|
+
weekdays of every nth week (`TUE%2`).
|
|
17
|
+
- `@every` schedules for periodic jobs (`@every 90s`, `@every 1h30m`),
|
|
18
|
+
firing at the multiples of their interval since the Unix epoch.
|
|
19
|
+
- `Robin::Cron.parse`, which returns a `Robin::Cron` or, for an `@every`
|
|
20
|
+
schedule, a `Robin::Cron::Every`.
|
|
21
|
+
|
|
10
22
|
## [0.1.0] - 2026-10-24
|
|
11
23
|
|
|
12
24
|
The first release. Everything is open source under the LGPL-3.0.
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center"><strong>Fast, reliable background jobs for Ruby. Every feature open source.</strong></p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="https://github.com/sferik/
|
|
8
|
+
<a href="https://github.com/sferik/robin/actions/workflows/perf.yml"><img src="https://raw.githubusercontent.com/sferik/robin/duel/badge/badge.svg" alt="Duel"></a>
|
|
9
9
|
<a href="https://github.com/sferik/robin/actions/workflows/test.yml"><img src="https://github.com/sferik/robin/actions/workflows/test.yml/badge.svg" alt="Test"></a>
|
|
10
10
|
<a href="https://github.com/sferik/robin/actions/workflows/lint.yml"><img src="https://github.com/sferik/robin/actions/workflows/lint.yml/badge.svg" alt="Lint"></a>
|
|
11
11
|
<a href="https://github.com/sferik/robin/actions/workflows/mutant.yml"><img src="https://github.com/sferik/robin/actions/workflows/mutant.yml/badge.svg" alt="Mutant"></a>
|
|
@@ -683,10 +683,23 @@ Robin.configure_server do |config|
|
|
|
683
683
|
cron.register "*/5 * * * *", "PruneSessions"
|
|
684
684
|
cron.register "0 9 * * MON-FRI", "DailyDigest", queue: "mailers", tz: "America/New_York"
|
|
685
685
|
cron.register "@hourly", "SyncInventory", args: ["warehouse-1"], description: "Pull stock levels"
|
|
686
|
+
cron.register "0 9 * * MON#1", "MonthlyReport" # the first Monday of each month
|
|
687
|
+
cron.register "@every 90s", "PollFeeds"
|
|
686
688
|
end
|
|
687
689
|
end
|
|
688
690
|
```
|
|
689
691
|
|
|
692
|
+
Schedules are cron expressions (five fields, or six with seconds first)
|
|
693
|
+
or `@every` and an interval. Besides the standard syntax, cron
|
|
694
|
+
expressions take `L` or `-1` for the last day of the month (`-2` for
|
|
695
|
+
the one before it), `MON#2` for the second Monday of the month (`#-1` or
|
|
696
|
+
`#L` for the last), and `TUE%2` for Tuesdays of even weeks (`TUE%2+1` for
|
|
697
|
+
odd ones), as sidekiq-cron and sidekiq-scheduler do. `@every` takes days,
|
|
698
|
+
hours, minutes and seconds (`@every 1h30m`) and fires at the multiples
|
|
699
|
+
of its interval since the Unix epoch: `@every 15m` at :00, :15, :30 and
|
|
700
|
+
:45, and `@every 1d` at midnight UTC. So the ticks are the same whenever
|
|
701
|
+
a process starts.
|
|
702
|
+
|
|
690
703
|
Only the elected leader enqueues periodic jobs, and each tick is
|
|
691
704
|
deduplicated in Redis, so a job runs once per tick no matter how many
|
|
692
705
|
processes you run. After a leader failover, at most one missed tick is
|
data/lib/robin/cron.rb
CHANGED
|
@@ -12,11 +12,21 @@ module Robin
|
|
|
12
12
|
#
|
|
13
13
|
# Five fields (minute hour day-of-month month day-of-week), or six with a
|
|
14
14
|
# leading seconds field. Supports *, lists (1,2), ranges (1-5), steps
|
|
15
|
-
# (*/5, 10-40/10, 5/15), month and weekday names, ? (same as *),
|
|
16
|
-
#
|
|
17
|
-
# @
|
|
18
|
-
#
|
|
19
|
-
#
|
|
15
|
+
# (*/5, 10-40/10, 5/15), month and weekday names, ? (same as *), 7 as
|
|
16
|
+
# Sunday, and the @yearly, @annually, @monthly, @weekly, @daily,
|
|
17
|
+
# @midnight and @hourly shortcuts. When both day fields are restricted,
|
|
18
|
+
# a day matches if either does.
|
|
19
|
+
#
|
|
20
|
+
# Also fugit's additions, so schedules written for sidekiq-cron or
|
|
21
|
+
# sidekiq-scheduler read the same:
|
|
22
|
+
#
|
|
23
|
+
# L or -1 (day of month) the last day of the month, -2 the one
|
|
24
|
+
# before it, and so on
|
|
25
|
+
# MON#2, 1#-1, FRI#L the second Monday of the month, the last
|
|
26
|
+
# Monday, the last Friday (#1 to #5, #-1 to
|
|
27
|
+
# #-5)
|
|
28
|
+
# TUE%2, TUE%2+1 Tuesdays of even weeks, of odd weeks
|
|
29
|
+
# (weeks counted from Monday, 2018-12-31)
|
|
20
30
|
#
|
|
21
31
|
# Time zones: nil (the system zone), "UTC", fixed offsets ("+05:30"), or
|
|
22
32
|
# IANA names ("Europe/Berlin", needs the tzinfo gem). Wall-clock times
|
|
@@ -33,13 +43,37 @@ module Robin
|
|
|
33
43
|
DAY_NAMES = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday].freeze
|
|
34
44
|
MONTH_NAMES = %w[January February March April May June July August September October November December].freeze
|
|
35
45
|
ANY = %w[* ?].freeze
|
|
46
|
+
# A day of the month counted from its end: L (or LAST) is -1.
|
|
47
|
+
FROM_END = /\A(?:-(?<n>\d+)|L|LAST)\z/i
|
|
48
|
+
# MON#2, MON#-1, MON#L: the nth weekday of the month.
|
|
49
|
+
NTH = /\A(?<day>\w+)#(?:(?<n>-?[1-5])|L|LAST)\z/i
|
|
50
|
+
# TUE%2, TUE%3+1: that weekday in the weeks whose number modulo
|
|
51
|
+
# +every+ is +offset+.
|
|
52
|
+
CYCLE = /\A(?<day>\w+)%(?<every>\d+)(?:\+(?<offset>\d+))?\z/
|
|
53
|
+
# The days of the month whose ordinal doesn't end in "th".
|
|
54
|
+
ORDINAL_SUFFIXES = {1 => "st", 2 => "nd", 3 => "rd", 21 => "st", 22 => "nd", 23 => "rd", 31 => "st"}.freeze
|
|
55
|
+
# Week 0 of those cycles: fugit's (et-orbi's) reference Monday,
|
|
56
|
+
# 2018-12-31, in days since the Unix epoch.
|
|
57
|
+
WEEK_ZERO = 17_896
|
|
58
|
+
# The months' lengths, outside leap years.
|
|
59
|
+
MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].freeze
|
|
36
60
|
|
|
37
61
|
# Upper bound on search steps. Every step moves to the next candidate
|
|
38
62
|
# month, day, hour, minute or second, so this spans decades even for
|
|
39
63
|
# the sparsest expressions; impossible ones (Feb 30) give up with nil.
|
|
40
64
|
MAX_STEPS = 20_000
|
|
41
65
|
|
|
42
|
-
attr_reader :expression, :tz, :zone, :seconds, :minutes, :hours, :days, :months, :weekdays
|
|
66
|
+
attr_reader :expression, :tz, :zone, :seconds, :minutes, :hours, :days, :months, :weekdays,
|
|
67
|
+
:days_from_end, :nth_weekdays, :weekday_cycles
|
|
68
|
+
|
|
69
|
+
# A Cron, or an Every for "@every" schedules (which take no zone).
|
|
70
|
+
def self.parse(expression, tz: nil)
|
|
71
|
+
text = expression.to_s.strip
|
|
72
|
+
return new(text, tz: tz) unless Every::PREFIX.match?(text)
|
|
73
|
+
raise ParseError, "#{text.inspect} counts from the Unix epoch and takes no time zone" if tz
|
|
74
|
+
|
|
75
|
+
Every.new(text)
|
|
76
|
+
end
|
|
43
77
|
|
|
44
78
|
def initialize(expression, tz: nil)
|
|
45
79
|
@expression = expression.to_s.strip
|
|
@@ -160,19 +194,39 @@ module Robin
|
|
|
160
194
|
def every(step, unit) = (step == 1) ? "every #{unit}" : "every #{step} #{unit}s"
|
|
161
195
|
|
|
162
196
|
def describe_days
|
|
163
|
-
days = [describe_dom
|
|
197
|
+
days = [describe_dom].compact.concat(describe_dow)
|
|
164
198
|
days.join(" or ") unless days.empty?
|
|
165
199
|
end
|
|
166
200
|
|
|
167
201
|
def describe_dom
|
|
168
|
-
return
|
|
202
|
+
return if @dom_any
|
|
169
203
|
|
|
170
|
-
|
|
204
|
+
days = @days_from_end.map { |n| "the #{from_end(n)} day" }
|
|
205
|
+
days.unshift("day #{@days.join(", ")}") unless @days.empty?
|
|
206
|
+
"on #{days.join(" and ")} of the month"
|
|
171
207
|
end
|
|
172
208
|
|
|
209
|
+
# A phrase for each kind of weekday.
|
|
173
210
|
def describe_dow
|
|
174
|
-
return if @dow_any
|
|
211
|
+
return [] if @dow_any
|
|
212
|
+
|
|
213
|
+
days = @nth_weekdays.map { |day, n| "on the #{from_end(n)} #{DAY_NAMES.fetch(day)} of the month" }
|
|
214
|
+
days.concat(@weekday_cycles.map { |day, every, offset| "on #{DAY_NAMES.fetch(day)} every #{every} weeks (week #{offset})" })
|
|
215
|
+
days.unshift(describe_weekdays) unless @weekdays.empty?
|
|
216
|
+
days
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# "1st" or "2nd" for 1 or 2, "last" for -1, "2nd-to-last" for -2.
|
|
220
|
+
def from_end(n)
|
|
221
|
+
return ordinal(n) if n.positive?
|
|
222
|
+
|
|
223
|
+
(n == -1) ? "last" : "#{ordinal(-n)}-to-last"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# 1 to 31 only.
|
|
227
|
+
def ordinal(n) = "#{n}#{ORDINAL_SUFFIXES.fetch(n, "th")}"
|
|
175
228
|
|
|
229
|
+
def describe_weekdays
|
|
176
230
|
case @weekdays
|
|
177
231
|
when [1, 2, 3, 4, 5] then "on weekdays"
|
|
178
232
|
when [0, 6] then "on weekends"
|
|
@@ -193,15 +247,57 @@ module Robin
|
|
|
193
247
|
@seconds = field(sec, 0, 59)
|
|
194
248
|
@minutes = field(min, 0, 59)
|
|
195
249
|
@hours = field(hour, 0, 23)
|
|
196
|
-
@
|
|
197
|
-
@days = @last_dom ? [] : field(dom, 1, 31)
|
|
250
|
+
@days, @days_from_end = days_of_month(dom)
|
|
198
251
|
@months = field(month, 1, 12, MONTHS)
|
|
199
|
-
weekdays =
|
|
200
|
-
@weekdays = weekdays.include?(7) ? ((weekdays - [7]) | [0]).sort : weekdays
|
|
252
|
+
@weekdays, @nth_weekdays, @weekday_cycles = days_of_week(dow)
|
|
201
253
|
@dom_any = ANY.include?(dom)
|
|
202
254
|
@dow_any = ANY.include?(dow)
|
|
203
255
|
end
|
|
204
256
|
|
|
257
|
+
# The days counted from the start of the month, and those counted from
|
|
258
|
+
# its end (-1 for the last).
|
|
259
|
+
def days_of_month(text)
|
|
260
|
+
from_end, days = text.split(",").partition { |part| FROM_END.match?(part) }
|
|
261
|
+
from_end = from_end.map do |part|
|
|
262
|
+
n = (count = part[FROM_END, :n]) ? Integer(count, 10) : 1
|
|
263
|
+
raise ParseError, "#{part.inspect} is out of range -31 to -1" unless n.between?(1, 31)
|
|
264
|
+
|
|
265
|
+
-n
|
|
266
|
+
end
|
|
267
|
+
[field(days.join(","), 1, 31), from_end.uniq.sort]
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# The weekdays, the nth weekdays of the month ([day, n] each), and the
|
|
271
|
+
# weekdays in cycles of weeks ([day, every, offset] each).
|
|
272
|
+
def days_of_week(text)
|
|
273
|
+
nth = [] #: Array[[Integer, Integer]]
|
|
274
|
+
cycles = [] #: Array[[Integer, Integer, Integer]]
|
|
275
|
+
plain = text.split(",").reject do |part|
|
|
276
|
+
if (m = NTH.match(part))
|
|
277
|
+
nth << [weekday(m), (n = m[:n]) ? Integer(n) : -1]
|
|
278
|
+
elsif (m = CYCLE.match(part))
|
|
279
|
+
every = m[:every] #: String
|
|
280
|
+
every = Integer(every, 10)
|
|
281
|
+
raise ParseError, "bad cycle in #{part.inspect}" unless every.positive?
|
|
282
|
+
|
|
283
|
+
cycles << [weekday(m), every, Integer(m[:offset] || "0", 10) % every]
|
|
284
|
+
elsif part.match?(/[#%]/)
|
|
285
|
+
raise ParseError, "#{part.inspect} isn't a weekday with #1 to #5, #-1 to #-5, #L or %n"
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
weekdays = field(plain.join(","), 0, 7, DAYS)
|
|
289
|
+
[weekdays.include?(7) ? ((weekdays - [7]) | [0]).sort : weekdays, nth.uniq.sort, cycles.uniq.sort]
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# The weekday (0 for Sunday) a #n or %n part names.
|
|
293
|
+
def weekday(match)
|
|
294
|
+
name = match[:day] #: String
|
|
295
|
+
day = value(name, DAYS)
|
|
296
|
+
raise ParseError, "#{match.string.inspect} is out of range 0-7" unless day <= 7
|
|
297
|
+
|
|
298
|
+
day % 7
|
|
299
|
+
end
|
|
300
|
+
|
|
205
301
|
def field(text, min, max, names = {})
|
|
206
302
|
values = text.split(",").flat_map do |part|
|
|
207
303
|
range, step = part.split("/", 2) #: [String, String] | [String]
|
|
@@ -231,14 +327,82 @@ module Robin
|
|
|
231
327
|
end
|
|
232
328
|
|
|
233
329
|
def day_match?(w)
|
|
234
|
-
dom = @
|
|
235
|
-
dow = @weekdays.include?(w.wday)
|
|
330
|
+
dom = @days.include?(w.day) || @days_from_end.include?(w.day - last_day(w) - 1)
|
|
331
|
+
dow = @weekdays.include?(w.wday) || weekday_match?(w)
|
|
236
332
|
if @dom_any then dow
|
|
237
333
|
elsif @dow_any then dom
|
|
238
334
|
else dom || dow
|
|
239
335
|
end
|
|
240
336
|
end
|
|
241
337
|
|
|
338
|
+
# Whether +w+ is one of the nth weekdays of its month, or a weekday in
|
|
339
|
+
# one of the cycles of weeks.
|
|
340
|
+
def weekday_match?(w)
|
|
341
|
+
wday = w.wday
|
|
342
|
+
@nth_weekdays.any? { |day, n| day == wday && n == (n.positive? ? ((w.day - 1) / 7) + 1 : -((last_day(w) - w.day) / 7) - 1) } ||
|
|
343
|
+
@weekday_cycles.any? { |day, every, offset| day == wday && week(w) % every == offset }
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# The last day of +w+'s month (without allocating, as a Date would).
|
|
347
|
+
def last_day(w) = (w.month == 2 && Date.gregorian_leap?(w.year)) ? 29 : MONTH_DAYS.fetch(w.month - 1)
|
|
348
|
+
|
|
349
|
+
# The number of +w+'s week (Monday to Sunday) since WEEK_ZERO. +w+ is
|
|
350
|
+
# a wall clock time, so its seconds since the epoch count its local
|
|
351
|
+
# days.
|
|
352
|
+
def week(w) = ((Integer(w) / 86_400) - WEEK_ZERO) / 7
|
|
353
|
+
|
|
354
|
+
# A schedule that fires every so often, at the multiples of its
|
|
355
|
+
# interval since the Unix epoch: "@every 5m" fires at :00, :05, :10
|
|
356
|
+
# and so on of every hour, "@every 90s" at 00:00:00, 00:01:30 and so
|
|
357
|
+
# on, and "@every 1d" at midnight UTC. So every process works out the
|
|
358
|
+
# same ticks, whenever it started. Intervals are days, hours, minutes
|
|
359
|
+
# and seconds, in any combination ("@every 1h30m").
|
|
360
|
+
#
|
|
361
|
+
# every = Robin::Cron.parse("@every 15m")
|
|
362
|
+
# every.interval # => 900
|
|
363
|
+
# every.description # => "every 15 minutes"
|
|
364
|
+
class Every
|
|
365
|
+
PREFIX = /\A@every\b/i
|
|
366
|
+
FORMAT = /\A@every\s+(?<interval>(?:\d+[dhms])+)\z/i
|
|
367
|
+
UNITS = {"d" => 86_400, "h" => 3_600, "m" => 60, "s" => 1}.freeze
|
|
368
|
+
UNIT_NAMES = {86_400 => "day", 3_600 => "hour", 60 => "minute", 1 => "second"}.freeze
|
|
369
|
+
|
|
370
|
+
attr_reader :expression, :interval
|
|
371
|
+
|
|
372
|
+
def initialize(expression)
|
|
373
|
+
@expression = expression.to_s.strip
|
|
374
|
+
interval = FORMAT.match(@expression)&.[](:interval)
|
|
375
|
+
raise ParseError, %(#{@expression.inspect} isn't "@every" and an interval, like "@every 5m" or "@every 1h30m") unless interval
|
|
376
|
+
|
|
377
|
+
parts = interval.scan(/(\d+)(\w)/) #: Array[[String, String]]
|
|
378
|
+
@interval = parts.sum { |count, unit| Integer(count, 10) * UNITS.fetch(unit.downcase) }
|
|
379
|
+
raise ParseError, "#{@expression.inspect} has no interval" unless @interval.positive?
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
def to_s = @expression
|
|
383
|
+
|
|
384
|
+
def inspect = "#<Robin::Cron::Every #{@expression.inspect}>"
|
|
385
|
+
|
|
386
|
+
# Whether +time+ (to the second) is a tick.
|
|
387
|
+
def match?(time) = (Integer(time) % @interval).zero?
|
|
388
|
+
|
|
389
|
+
# The first tick strictly after +from+, in UTC.
|
|
390
|
+
def next_time(from = Time.now) = Time.at(((Integer(from) / @interval) + 1) * @interval).utc
|
|
391
|
+
|
|
392
|
+
# The last tick strictly before +from+, in UTC.
|
|
393
|
+
def previous_time(from = Time.now) = Time.at(((from.to_r.ceil - 1) / @interval) * @interval).utc
|
|
394
|
+
|
|
395
|
+
# "every 5 minutes", "every hour", "every 1 hour 30 minutes".
|
|
396
|
+
def description
|
|
397
|
+
rest = @interval
|
|
398
|
+
parts = UNIT_NAMES.filter_map do |size, name|
|
|
399
|
+
count, rest = rest.divmod(size)
|
|
400
|
+
"#{count} #{name}#{"s" unless count == 1}" if count.positive?
|
|
401
|
+
end
|
|
402
|
+
"every #{parts.one? ? parts.join.delete_prefix("1 ") : parts.join(" ")}"
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
242
406
|
# Converts between UTC instants and "wall clock" times, represented as
|
|
243
407
|
# UTC Time objects holding the local fields.
|
|
244
408
|
module Zone
|
data/lib/robin/periodic.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Robin
|
|
|
10
10
|
# cron.register "*/5 * * * *", "CleanupJob"
|
|
11
11
|
# cron.register "0 3 * * *", "NightlyReport", queue: "low", args: ["daily"],
|
|
12
12
|
# tz: "America/Chicago", description: "Email the nightly report"
|
|
13
|
+
# cron.register "@every 90s", "PollFeeds" # see Cron::Every
|
|
13
14
|
# end
|
|
14
15
|
# end
|
|
15
16
|
#
|
|
@@ -68,7 +69,7 @@ module Robin
|
|
|
68
69
|
def register(cron, klass, queue: nil, args: [], tz: nil, description: nil, **options)
|
|
69
70
|
# @type ivar @problems: Array[String]
|
|
70
71
|
begin
|
|
71
|
-
Cron.
|
|
72
|
+
Cron.parse(cron, tz: tz) # validate early
|
|
72
73
|
rescue Cron::ParseError => e
|
|
73
74
|
raise unless @problems
|
|
74
75
|
|
|
@@ -115,7 +116,7 @@ module Robin
|
|
|
115
116
|
return if entries.empty?
|
|
116
117
|
|
|
117
118
|
write_registry(config, entries)
|
|
118
|
-
crons = entries.transform_values { |e| Cron.
|
|
119
|
+
crons = entries.transform_values { |e| Cron.parse(e.fetch("cron"), tz: e.fetch("tz")) }
|
|
119
120
|
Thread.new do
|
|
120
121
|
Thread.current.name = "robin.periodic"
|
|
121
122
|
run_loop(launcher, entries, crons)
|
|
@@ -318,7 +319,7 @@ module Robin
|
|
|
318
319
|
|
|
319
320
|
# nil for definitions this version can't parse.
|
|
320
321
|
def parse(entry)
|
|
321
|
-
Cron.
|
|
322
|
+
Cron.parse(entry.fetch("cron"), tz: entry["tz"])
|
|
322
323
|
rescue Cron::ParseError
|
|
323
324
|
nil
|
|
324
325
|
end
|
data/lib/robin/version.rb
CHANGED
|
Binary file
|
data/sig/manifest.yaml
CHANGED
data/sig/robin/cron.rbs
CHANGED
|
@@ -12,8 +12,13 @@ module Robin
|
|
|
12
12
|
MONTH_NAMES: Array[String]
|
|
13
13
|
ANY: Array[String]
|
|
14
14
|
MAX_STEPS: Integer
|
|
15
|
+
FROM_END: Regexp
|
|
16
|
+
NTH: Regexp
|
|
17
|
+
CYCLE: Regexp
|
|
18
|
+
ORDINAL_SUFFIXES: Hash[Integer, String]
|
|
19
|
+
WEEK_ZERO: Integer
|
|
20
|
+
MONTH_DAYS: Array[Integer]
|
|
15
21
|
|
|
16
|
-
@last_dom: bool
|
|
17
22
|
@dom_any: bool
|
|
18
23
|
@dow_any: bool
|
|
19
24
|
|
|
@@ -32,6 +37,22 @@ module Robin
|
|
|
32
37
|
attr_reader months: Array[Integer]
|
|
33
38
|
attr_reader weekdays: Array[Integer]
|
|
34
39
|
|
|
40
|
+
# Days of the month counted from its end: -1 for the last.
|
|
41
|
+
attr_reader days_from_end: Array[Integer]
|
|
42
|
+
|
|
43
|
+
# The nth weekdays of the month: [weekday, n], n from 1 to 5 or -1
|
|
44
|
+
# (the last) to -5.
|
|
45
|
+
attr_reader nth_weekdays: Array[[Integer, Integer]]
|
|
46
|
+
|
|
47
|
+
# Weekdays in cycles of weeks: [weekday, every, offset].
|
|
48
|
+
attr_reader weekday_cycles: Array[[Integer, Integer, Integer]]
|
|
49
|
+
|
|
50
|
+
# A cron expression's schedule or an @every one.
|
|
51
|
+
type schedule = Cron | Every
|
|
52
|
+
|
|
53
|
+
# A Cron, or an Every for "@every" schedules (which take no zone).
|
|
54
|
+
def self.parse: (_ToS expression, ?tz: String?) -> schedule
|
|
55
|
+
|
|
35
56
|
def initialize: (_ToS expression, ?tz: String?) -> void
|
|
36
57
|
|
|
37
58
|
def to_s: () -> String
|
|
@@ -69,18 +90,64 @@ module Robin
|
|
|
69
90
|
|
|
70
91
|
def describe_dom: () -> String?
|
|
71
92
|
|
|
72
|
-
def describe_dow: () -> String
|
|
93
|
+
def describe_dow: () -> Array[String]
|
|
94
|
+
|
|
95
|
+
def describe_weekdays: () -> String
|
|
96
|
+
|
|
97
|
+
def from_end: (Integer n) -> String
|
|
98
|
+
|
|
99
|
+
def ordinal: (Integer n) -> String
|
|
73
100
|
|
|
74
101
|
def describe_months: () -> String?
|
|
75
102
|
|
|
76
103
|
def parse: (String expr) -> void
|
|
77
104
|
|
|
105
|
+
def days_of_month: (String text) -> [Array[Integer], Array[Integer]]
|
|
106
|
+
|
|
107
|
+
def days_of_week: (String text) -> [Array[Integer], Array[[Integer, Integer]], Array[[Integer, Integer, Integer]]]
|
|
108
|
+
|
|
109
|
+
def weekday: (MatchData match) -> Integer
|
|
110
|
+
|
|
78
111
|
def field: (String text, Integer min, Integer max, ?Hash[String, Integer] names) -> Array[Integer]
|
|
79
112
|
|
|
80
113
|
def value: (String text, Hash[String, Integer] names) -> Integer
|
|
81
114
|
|
|
82
115
|
def day_match?: (Time w) -> bool
|
|
83
116
|
|
|
117
|
+
def weekday_match?: (Time w) -> bool
|
|
118
|
+
|
|
119
|
+
def last_day: (Time w) -> Integer
|
|
120
|
+
|
|
121
|
+
def week: (Time w) -> Integer
|
|
122
|
+
|
|
123
|
+
# A schedule firing at the multiples of an interval since the Unix
|
|
124
|
+
# epoch ("@every 5m").
|
|
125
|
+
class Every
|
|
126
|
+
PREFIX: Regexp
|
|
127
|
+
FORMAT: Regexp
|
|
128
|
+
UNITS: Hash[String, Integer]
|
|
129
|
+
UNIT_NAMES: Hash[Integer, String]
|
|
130
|
+
|
|
131
|
+
attr_reader expression: String
|
|
132
|
+
|
|
133
|
+
# In seconds.
|
|
134
|
+
attr_reader interval: Integer
|
|
135
|
+
|
|
136
|
+
def initialize: (_ToS expression) -> void
|
|
137
|
+
|
|
138
|
+
def to_s: () -> String
|
|
139
|
+
|
|
140
|
+
def inspect: () -> String
|
|
141
|
+
|
|
142
|
+
def match?: (Time time) -> bool
|
|
143
|
+
|
|
144
|
+
def next_time: (?Time from) -> Time
|
|
145
|
+
|
|
146
|
+
def previous_time: (?Time from) -> Time
|
|
147
|
+
|
|
148
|
+
def description: () -> String
|
|
149
|
+
end
|
|
150
|
+
|
|
84
151
|
# Converts between UTC instants and "wall clock" times (UTC Times
|
|
85
152
|
# holding the local fields).
|
|
86
153
|
module Zone
|
data/sig/robin/periodic.rbs
CHANGED
|
@@ -57,16 +57,16 @@ module Robin
|
|
|
57
57
|
|
|
58
58
|
# Enqueues the entries whose latest tick hasn't been claimed yet;
|
|
59
59
|
# returns their jids.
|
|
60
|
-
def self.tick: (Config config, Hash[String, entry] entries, Hash[String, Cron] crons, ?Time now, ?Hash[String, Integer] claimed) -> Array[String?]
|
|
60
|
+
def self.tick: (Config config, Hash[String, entry] entries, Hash[String, Cron::schedule] crons, ?Time now, ?Hash[String, Integer] claimed) -> Array[String?]
|
|
61
61
|
|
|
62
62
|
# Writes the entries to Redis as the periodic jobs, arming new ones.
|
|
63
63
|
def self.write_registry: (Config config, Hash[String, entry] entries) -> void
|
|
64
64
|
|
|
65
|
-
private def self.claim: (Config config, Array[tick] dues, Hash[String, Cron] crons, Time now, Hash[String, Integer] claimed) -> Array[tick]
|
|
65
|
+
private def self.claim: (Config config, Array[tick] dues, Hash[String, Cron::schedule] crons, Time now, Hash[String, Integer] claimed) -> Array[tick]
|
|
66
66
|
|
|
67
|
-
private def self.run_loop: (Launcher launcher, Hash[String, entry] entries, Hash[String, Cron] crons) -> void
|
|
67
|
+
private def self.run_loop: (Launcher launcher, Hash[String, entry] entries, Hash[String, Cron::schedule] crons) -> void
|
|
68
68
|
|
|
69
|
-
private def self.seconds_until_next: (Hash[String, Cron] crons, Time now) -> (Float | Integer)
|
|
69
|
+
private def self.seconds_until_next: (Hash[String, Cron::schedule] crons, Time now) -> (Float | Integer)
|
|
70
70
|
|
|
71
71
|
private def self.entry_problems: (entry entry) -> Array[String]
|
|
72
72
|
|
|
@@ -76,6 +76,6 @@ module Robin
|
|
|
76
76
|
|
|
77
77
|
private def self.record: (Config config, Array[[String, Integer, String?]] pushed, ?manual: bool) -> void
|
|
78
78
|
|
|
79
|
-
private def self.parse: (entry entry) -> Cron?
|
|
79
|
+
private def self.parse: (entry entry) -> Cron::schedule?
|
|
80
80
|
end
|
|
81
81
|
end
|