honker 0.3.1-aarch64-linux → 0.3.2-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c38234e0838f535413deed4153dffd480b4cf37cd0f48f66d3e719987fc19f5d
4
- data.tar.gz: '08c256f82beea177ade1375705a4dccb0b139759d49187e83cfb635ed65baadb'
3
+ metadata.gz: 33c55981d9fee54bdc95195926ab606cb3009256cc4b37be93da3b1c9df68094
4
+ data.tar.gz: b34e941647b41a46e79b2780c7694821d90920ce23cc020ad025c9f236667ca6
5
5
  SHA512:
6
- metadata.gz: 7443aeb793659c4188f6cd5271301cb0ee1244e379e91eabf48bfa1957d9e0b9d8eea8cbccb461b68ee673b9a1116c3890ed527c38148ab9019aaa8e1ad5c650
7
- data.tar.gz: b4f548ae7490587e6c16403242fd13c3bf1772caa1a19551c460edacb726e8c43220879acf77bc88baac4c9ff9ada33fe6649183c8812057706c9e7775a0ebc9
6
+ metadata.gz: d9ac00fb747fa76d436c1e9615ba3a0aae10b28a7f2b3b461df6c0a6973d6fceb32b4f99f7a6f50e71ff7f2515bc6d716bad18ab8eee6b22a52886a7879cf8a0
7
+ data.tar.gz: 194d1dd44b680abd5b42cb175291bd6785d2334680d24568f4fd4950201bc72ba126bc88ad2da77c418276175e0c0a4db33bb80d802d9466e5c397a460b2f11b
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
- # The underlying SQL is the same as `try_lock`, but keyed on our
60
- # existing `(name, owner)` pair so it refreshes rather than blocks.
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 honker_lock_acquire(?, ?, ?)",
63
+ "SELECT honker_lock_renew(?, ?, ?)",
64
64
  [@name, @owner, ttl_s],
65
65
  )[0] == 1
66
66
  end
@@ -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. Cron change recomputes next_fire_at from now.
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(?, ?)",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Honker
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Russell Romney