Skip to content

Commit 2d4dc7f

Browse files
jakubkosinskimpraglowski
authored andcommitted
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 25ddf3b commit 2d4dc7f

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

contrib/ruby_event_store-outbox/CHANGELOG.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1-
### 0.1.0 2025-03-25
1+
### unreleased
22

3-
* Add support for non-locking repository that is using `SKIP LOCKED` clause and doesn't use global locks.
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)
44

5-
### 0.0.30 2025-03-25
5+
### 0.1.0 2025-03-25
66

7-
* Fix an issue with `res_outbox` not starting due to inability to require `sidekiq`.
7+
- Add support for non-locking repository that is using `SKIP LOCKED` clause and doesn't use global locks.
8+
9+
### 0.0.30 2025-03-25
10+
11+
- Fix an issue with `res_outbox` not starting due to inability to require `sidekiq`.
812
Sidekiq is only available in a producer context, while res_outbox is a consumer.
913

10-
### 0.0.29 2025-03-25
14+
### 0.0.29 2025-03-25
1115

12-
* Fix an issue with uninitialized constant `RubyEventStore::Outbox::RetriableError` when using `bin/res_outbox`
16+
- Fix an issue with uninitialized constant `RubyEventStore::Outbox::RetriableError` when using `bin/res_outbox`
1317

14-
### 0.0.28 2024-04-12
18+
### 0.0.28 2024-04-12
1519

16-
* Fix issues that prevent res_outbox CLI from processing
17-
* Upgrade docker image base to ruby:3.2
20+
- Fix issues that prevent res_outbox CLI from processing
21+
- Upgrade docker image base to ruby:3.2
1822

19-
### 0.0.27 2024-04-12
23+
### 0.0.27 2024-04-12
2024

21-
* Fix issues that prevent res_outbox CLI from starting
25+
- Fix issues that prevent res_outbox CLI from starting
2226

23-
### 0.0.26 2024-04-12
27+
### 0.0.26 2024-04-12
2428

25-
* stop testing with sidekiq 5, start testing with sidekiq 7
26-
* get rid of deprecation warnings from sidekiq 7
27-
* predictable redis failures (like timeout errors) are now retried (once) instead of being treated like any other error (being logged)
28-
* instead of immediately starting with processing full batch size, exponential progress is implemented so that big messages OOMing the infrastructure can be pushed through
29+
- stop testing with sidekiq 5, start testing with sidekiq 7
30+
- get rid of deprecation warnings from sidekiq 7
31+
- predictable redis failures (like timeout errors) are now retried (once) instead of being treated like any other error (being logged)
32+
- instead of immediately starting with processing full batch size, exponential progress is implemented so that big messages OOMing the infrastructure can be pushed through
2933

30-
### 0.0.25 2022-05-27
34+
### 0.0.25 2022-05-27
3135

32-
* added ORDER BY when cleaning up with limit #1338
36+
- added ORDER BY when cleaning up with limit #1338
3337

3438
### 0.0.24
3539

36-
* fixed error with passing `--cleanup-limit` from CLI down to consumer
37-
* added missing specs for CLI options
38-
* added simple smoke spec to ensure CLI builds consumer without errors
39-
* dropped support for rails 5.2
40-
* dropped support for ruby 2.6
40+
- fixed error with passing `--cleanup-limit` from CLI down to consumer
41+
- added missing specs for CLI options
42+
- added simple smoke spec to ensure CLI builds consumer without errors
43+
- dropped support for rails 5.2
44+
- dropped support for ruby 2.6
4145

4246
### 0.0.23
4347

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
@@ -20,7 +20,7 @@ def process(record, now)
2020

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

2525
redis.call("LPUSH", "queue:#{queue}", payload)
2626

contrib/ruby_event_store-outbox/spec/consumer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module Outbox
3636
expect(redis.call("LLEN", "queue:default")).to eq(1)
3737
payload_in_redis = JSON.parse(redis.call("LINDEX", "queue:default", 0))
3838
expect(payload_in_redis).to include(JSON.parse(record.payload))
39-
expect(payload_in_redis["enqueued_at"]).to eq(clock.tick(locking ? 1 : 0).to_f)
39+
expect(payload_in_redis["enqueued_at"]).to eq(record.created_at.to_f)
4040
expect(record.enqueued_at).to eq(clock.tick(locking ? 1 : 0))
4141
expect(result).to be(true)
4242
expect(logger_output.string).to include("Sent 1 messages from outbox table")

0 commit comments

Comments
 (0)