Skip to content

Commit 5677949

Browse files
committed
Use record created_at as enqueued_at timestamp when pushing a job to Sidekiq
This allows Sidekiq to calculate the latency including the time a job has spent in outbox
1 parent 8582357 commit 5677949

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

contrib/ruby_event_store-outbox/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### unreleased
2+
3+
* change the timestamp reported in `enqueued_at` to Sidekiq when pushing jobs from the current time to the record created at timestamp (so that the latency reported in Sidekiq includes the time a job has spent in outbox)
4+
15
### 0.0.28 2024-04-12
26

37
* Fix issues that prevent res_outbox CLI from processing

contrib/ruby_event_store-outbox/lib/ruby_event_store/outbox/sidekiq_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def process(record, now)
1717

1818
queue = parsed_record["queue"]
1919
raise InvalidPayload.new("Missing queue") if queue.nil? || queue.empty?
20-
payload = JSON.generate(parsed_record.merge({ "enqueued_at" => now.to_f }))
20+
payload = JSON.generate(parsed_record.merge({ "enqueued_at" => record.created_at.to_f }))
2121

2222
redis.call("LPUSH", "queue:#{queue}", payload)
2323

contrib/ruby_event_store-outbox/spec/consumer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Outbox
4848
expect(redis.call("LLEN", "queue:default")).to eq(1)
4949
payload_in_redis = JSON.parse(redis.call("LINDEX", "queue:default", 0))
5050
expect(payload_in_redis).to include(JSON.parse(record.payload))
51-
expect(payload_in_redis["enqueued_at"]).to eq(clock.tick(1).to_f)
51+
expect(payload_in_redis["enqueued_at"]).to eq(record.created_at.to_f)
5252
expect(record.enqueued_at).to eq(clock.tick(1))
5353
expect(result).to eq(true)
5454
expect(logger_output.string).to include("Sent 1 messages from outbox table")

0 commit comments

Comments
 (0)