honker 0.3.1-aarch64-linux → 0.4.0-aarch64-linux
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/lib/honker/libhonker_ext.so +0 -0
- data/lib/honker/lock.rb +3 -3
- data/lib/honker/scheduler.rb +26 -18
- data/lib/honker/version.rb +1 -1
- 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: 39a7f01f1b35dceebfea6754acfabd9e898f5fe8ec390ef69de6251c09c684e9
|
|
4
|
+
data.tar.gz: b753cb93f5169011e41e69a61c6e12530b432e70961c857bed0b8bf4807edd07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7425991ab95ca1f1f21acaeef271f4a4611226e38b0c10f9a9b1957357a8602a2be1219d1228bc64e5a7fa20f85d4b689cae427057c45ca953e48a6f29bd722c
|
|
7
|
+
data.tar.gz: 6920aefd153b9ae612c35a82ca4f641d8e0d1c563de9f18a3abbe180be2e48079e6373572c9f305ba2c2f36b1b2913a1280f47b7229b1af35e6bf67141c6d6b6
|
data/lib/honker/libhonker_ext.so
CHANGED
|
Binary file
|
data/lib/honker/lock.rb
CHANGED
|
@@ -56,11 +56,11 @@ module Honker
|
|
|
56
56
|
|
|
57
57
|
# Extend the TTL. Returns true if we still hold the lock; false if
|
|
58
58
|
# it was stolen (the TTL elapsed and another owner acquired it).
|
|
59
|
-
#
|
|
60
|
-
# existing
|
|
59
|
+
# Uses honker_lock_renew — honker_lock_acquire does not refresh
|
|
60
|
+
# expires_at for an existing (name, owner) row.
|
|
61
61
|
def heartbeat(ttl_s:)
|
|
62
62
|
@db.db.get_first_row(
|
|
63
|
-
"SELECT
|
|
63
|
+
"SELECT honker_lock_renew(?, ?, ?)",
|
|
64
64
|
[@name, @owner, ttl_s],
|
|
65
65
|
)[0] == 1
|
|
66
66
|
end
|
data/lib/honker/scheduler.rb
CHANGED
|
@@ -43,13 +43,13 @@ module Honker
|
|
|
43
43
|
#
|
|
44
44
|
# Idempotent by `name`; registering the same name twice replaces
|
|
45
45
|
# the previous row.
|
|
46
|
-
def add(name:, queue:, cron: nil, schedule: nil, payload:, priority: 0, expires_s: nil)
|
|
46
|
+
def add(name:, queue:, cron: nil, schedule: nil, payload:, priority: 0, expires_s: nil, max_attempts: 3)
|
|
47
47
|
expr = schedule || cron
|
|
48
48
|
raise ArgumentError, "must provide cron: or schedule:" if expr.nil? || expr.empty?
|
|
49
49
|
|
|
50
50
|
@db.db.get_first_row(
|
|
51
|
-
"SELECT honker_scheduler_register(?, ?, ?, ?, ?, ?)",
|
|
52
|
-
[name, queue, expr, JSON.dump(payload), priority, expires_s],
|
|
51
|
+
"SELECT honker_scheduler_register(?, ?, ?, ?, ?, ?, ?)",
|
|
52
|
+
[name, queue, expr, JSON.dump(payload), priority, expires_s, max_attempts],
|
|
53
53
|
)
|
|
54
54
|
@db.mark_updated
|
|
55
55
|
nil
|
|
@@ -105,7 +105,7 @@ module Honker
|
|
|
105
105
|
|
|
106
106
|
# Return every registered schedule with current state. Each entry
|
|
107
107
|
# is a Hash with: name, queue, cron_expr, payload (JSON string),
|
|
108
|
-
# priority, expires_s, next_fire_at, enabled.
|
|
108
|
+
# priority, expires_s, next_fire_at, enabled, max_attempts.
|
|
109
109
|
def list
|
|
110
110
|
raw = @db.db.get_first_row("SELECT honker_scheduler_list()")[0]
|
|
111
111
|
return [] if raw.nil? || raw.empty?
|
|
@@ -115,9 +115,10 @@ module Honker
|
|
|
115
115
|
|
|
116
116
|
# Mutate fields in place. Pass only the kwargs you want changed
|
|
117
117
|
# (omitting a kwarg leaves the field alone). `payload: nil`
|
|
118
|
-
# writes JSON null
|
|
118
|
+
# writes JSON null; `max_attempts: nil` resets to default 3.
|
|
119
|
+
# Cron change recomputes next_fire_at from now.
|
|
119
120
|
# Returns true iff a row was updated.
|
|
120
|
-
def update(name, schedule: UNSET, cron: UNSET, payload: UNSET, priority: UNSET, expires_s: UNSET)
|
|
121
|
+
def update(name, schedule: UNSET, cron: UNSET, payload: UNSET, priority: UNSET, expires_s: UNSET, max_attempts: UNSET)
|
|
121
122
|
expr = nil
|
|
122
123
|
expr = schedule if schedule != UNSET
|
|
123
124
|
expr = cron if expr.nil? && cron != UNSET
|
|
@@ -126,13 +127,16 @@ module Honker
|
|
|
126
127
|
priority_arg = (priority == UNSET) ? nil : priority
|
|
127
128
|
touch_expires = (expires_s == UNSET) ? 0 : 1
|
|
128
129
|
expires_arg = (expires_s == UNSET) ? nil : expires_s
|
|
130
|
+
touch_max_attempts = (max_attempts == UNSET) ? 0 : 1
|
|
131
|
+
max_attempts_arg = (max_attempts == UNSET) ? nil : max_attempts
|
|
129
132
|
|
|
130
|
-
any_field = !expr.nil? || payload != UNSET || priority != UNSET || expires_s != UNSET
|
|
133
|
+
any_field = !expr.nil? || payload != UNSET || priority != UNSET || expires_s != UNSET || max_attempts != UNSET
|
|
131
134
|
return false unless any_field
|
|
132
135
|
|
|
133
136
|
n = @db.db.get_first_row(
|
|
134
|
-
"SELECT honker_scheduler_update(?, ?, ?, ?, ?, ?)",
|
|
135
|
-
[name, expr, payload_arg, priority_arg, expires_arg, touch_expires
|
|
137
|
+
"SELECT honker_scheduler_update(?, ?, ?, ?, ?, ?, ?, ?)",
|
|
138
|
+
[name, expr, payload_arg, priority_arg, expires_arg, touch_expires,
|
|
139
|
+
max_attempts_arg, touch_max_attempts],
|
|
136
140
|
)[0]
|
|
137
141
|
@db.mark_updated if n.positive?
|
|
138
142
|
n.positive?
|
|
@@ -187,18 +191,15 @@ module Honker
|
|
|
187
191
|
def leader_loop(owner, stop_fn)
|
|
188
192
|
last_heartbeat = monotonic_now
|
|
189
193
|
until stop_fn.call
|
|
194
|
+
still_ours = lock_renew(LEADER_LOCK, owner, LOCK_TTL_S)
|
|
195
|
+
# IMPORTANT: if refresh failed, a new leader has the lock.
|
|
196
|
+
# Break out before ticking so we don't double-fire.
|
|
197
|
+
return unless still_ours
|
|
198
|
+
|
|
199
|
+
last_heartbeat = monotonic_now
|
|
190
200
|
# tick errors escape up to `run`, which releases the lock in
|
|
191
201
|
# its `ensure` before re-raising.
|
|
192
202
|
tick
|
|
193
|
-
if monotonic_now - last_heartbeat >= HEARTBEAT_S
|
|
194
|
-
still_ours = lock_try_acquire(LEADER_LOCK, owner, LOCK_TTL_S)
|
|
195
|
-
# IMPORTANT: if refresh failed, a new leader has the lock.
|
|
196
|
-
# Break out of the leader loop so we don't double-fire. This
|
|
197
|
-
# is the bug the Rust binding fixed; don't reintroduce it.
|
|
198
|
-
return unless still_ours
|
|
199
|
-
|
|
200
|
-
last_heartbeat = monotonic_now
|
|
201
|
-
end
|
|
202
203
|
|
|
203
204
|
wait_s = HEARTBEAT_S - (monotonic_now - last_heartbeat)
|
|
204
205
|
wait_s = 0 if wait_s.negative?
|
|
@@ -239,6 +240,13 @@ module Honker
|
|
|
239
240
|
)[0] == 1
|
|
240
241
|
end
|
|
241
242
|
|
|
243
|
+
def lock_renew(name, owner, ttl_s)
|
|
244
|
+
@db.db.get_first_row(
|
|
245
|
+
"SELECT honker_lock_renew(?, ?, ?)",
|
|
246
|
+
[name, owner, ttl_s],
|
|
247
|
+
)[0] == 1
|
|
248
|
+
end
|
|
249
|
+
|
|
242
250
|
def lock_release(name, owner)
|
|
243
251
|
@db.db.get_first_row(
|
|
244
252
|
"SELECT honker_lock_release(?, ?)",
|
data/lib/honker/version.rb
CHANGED