Skip to content

Commit aae33fe

Browse files
committed
Make HeartbeatProcess#tick! lease argument backward-compatible
The lease parameter was added to tick! in v0.85.0 but callers in the monolith (MultiTick#heartbeat) still use the old 1-arg signature. Make lease optional so existing callers work without changes. Bump ci-queue to v0.94.0.
1 parent 22b2781 commit aae33fe

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

ruby/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ci-queue (0.93.0)
4+
ci-queue (0.94.0)
55
logger
66

77
GEM

ruby/lib/ci/queue/redis/base.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ def shutdown!
318318
end
319319
end
320320

321-
def tick!(id, lease)
322-
send_message(TICK_COMMAND, id: id, lease: lease.to_s)
321+
def tick!(id, lease = nil)
322+
payload = { id: id }
323+
payload[:lease] = lease.to_s if lease
324+
send_message(TICK_COMMAND, **payload)
323325
@restart_attempts = 0
324326
rescue IOError, Errno::EPIPE => error
325327
@restart_attempts = (@restart_attempts || 0) + 1

ruby/lib/ci/queue/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module CI
44
module Queue
5-
VERSION = '0.93.0'
5+
VERSION = '0.94.0'
66
DEV_SCRIPTS_ROOT = ::File.expand_path('../../../../../redis', __FILE__)
77
RELEASE_SCRIPTS_ROOT = ::File.expand_path('../redis', __FILE__)
88
end

ruby/test/ci/queue/redis/heartbeat_process_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,21 @@ def test_tick_sends_valid_tick_payload
108108

109109
assert_equal ["tick!", { "id" => "test_id", "lease" => "lease_id" }], JSON.parse(payload)
110110
end
111+
112+
def test_tick_without_lease_omits_lease_from_payload
113+
pipe = FakePipe.new
114+
@hp.instance_variable_set(:@pipe, pipe)
115+
116+
@hp.tick!("test_id")
117+
118+
raw = pipe.buffer
119+
header_size = [0].pack("L").bytesize
120+
size = raw.byteslice(0, header_size).unpack1("L")
121+
payload = raw.byteslice(header_size, size)
122+
123+
parsed = JSON.parse(payload)
124+
assert_equal "tick!", parsed[0]
125+
assert_equal "test_id", parsed[1]["id"]
126+
refute parsed[1].key?("lease"), "lease should be omitted when not provided"
127+
end
111128
end

0 commit comments

Comments
 (0)