redstream 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/lib/redstream/delayer.rb +3 -3
- data/lib/redstream/producer.rb +4 -4
- data/lib/redstream/version.rb +1 -1
- data/spec/redstream/delayer_spec.rb +4 -4
- data/spec/redstream/trimmer_spec.rb +3 -3
- data/spec/redstream_spec.rb +5 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb01602a9b0e51f896989d59b5e2b16f333c7ea0317f31c5235696bc49145013
|
4
|
+
data.tar.gz: 747f63e94c847be8d371e60098f9348f30531587b821ac019c873c10d51dd766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19541261544b2d32168b8e290e402b5c9dedcf54868dee1dbb556bfa5cacf41a091fbff391605a734a6c1bf5eeaf6b33127660b190245166e1340a777c5e433d
|
7
|
+
data.tar.gz: 74426b36ca249b2da61f436f195d6811245038835492321009d063f78226cfdc7e099a4e17fe9910588ebc3f9bc6e21bec8e600959e0e5f8c2e77425ccda7023
|
data/.github/workflows/test.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/redstream/delayer.rb
CHANGED
@@ -48,7 +48,7 @@ module Redstream
|
|
48
48
|
def run_once
|
49
49
|
@consumer.run_once do |messages|
|
50
50
|
messages.each do |message|
|
51
|
-
seconds_to_sleep = message.message_id.to_f / 1_000 + @delay.to_f - Time.now.to_f
|
51
|
+
seconds_to_sleep = (message.message_id.to_f / 1_000) + @delay.to_f - Time.now.to_f
|
52
52
|
|
53
53
|
if seconds_to_sleep > 0
|
54
54
|
if @batch.size > 0
|
@@ -85,11 +85,11 @@ module Redstream
|
|
85
85
|
Redstream.connection_pool.with do |redis|
|
86
86
|
redis.pipelined do
|
87
87
|
@batch.each do |message|
|
88
|
-
redis.xadd
|
88
|
+
redis.xadd(Redstream.stream_key_name(@stream_name), { payload: message.fields["payload"] })
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
redis.xdel
|
92
|
+
redis.xdel(Redstream.stream_key_name("#{@stream_name}.delay"), @batch.map(&:message_id))
|
93
93
|
end
|
94
94
|
|
95
95
|
@batch = []
|
data/lib/redstream/producer.rb
CHANGED
@@ -72,7 +72,7 @@ module Redstream
|
|
72
72
|
Redstream.connection_pool.with do |redis|
|
73
73
|
redis.pipelined do
|
74
74
|
slice.each do |object|
|
75
|
-
redis.xadd(Redstream.stream_key_name("#{stream_name(object)}.delay"), payload: JSON.dump(object.redstream_payload))
|
75
|
+
redis.xadd(Redstream.stream_key_name("#{stream_name(object)}.delay"), { payload: JSON.dump(object.redstream_payload) })
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -97,7 +97,7 @@ module Redstream
|
|
97
97
|
Redstream.connection_pool.with do |redis|
|
98
98
|
redis.pipelined do
|
99
99
|
slice.each do |object, index|
|
100
|
-
redis.xadd(Redstream.stream_key_name(stream_name(object)), payload: JSON.dump(object.redstream_payload))
|
100
|
+
redis.xadd(Redstream.stream_key_name(stream_name(object)), { payload: JSON.dump(object.redstream_payload) })
|
101
101
|
redis.xdel(Redstream.stream_key_name("#{stream_name(object)}.delay"), delay_message_ids[index]) if delay_message_ids
|
102
102
|
end
|
103
103
|
end
|
@@ -117,7 +117,7 @@ module Redstream
|
|
117
117
|
|
118
118
|
def delay(object)
|
119
119
|
Redstream.connection_pool.with do |redis|
|
120
|
-
res = redis.xadd(Redstream.stream_key_name("#{stream_name(object)}.delay"), payload: JSON.dump(object.redstream_payload))
|
120
|
+
res = redis.xadd(Redstream.stream_key_name("#{stream_name(object)}.delay"), { payload: JSON.dump(object.redstream_payload) })
|
121
121
|
redis.wait(@wait, 0) if @wait
|
122
122
|
res
|
123
123
|
end
|
@@ -133,7 +133,7 @@ module Redstream
|
|
133
133
|
def queue(object, delay_message_id: nil)
|
134
134
|
Redstream.connection_pool.with do |redis|
|
135
135
|
redis.pipelined do
|
136
|
-
redis.xadd(Redstream.stream_key_name(stream_name(object)), payload: JSON.dump(object.redstream_payload))
|
136
|
+
redis.xadd(Redstream.stream_key_name(stream_name(object)), { payload: JSON.dump(object.redstream_payload) })
|
137
137
|
redis.xdel(Redstream.stream_key_name("#{stream_name(object)}.delay"), delay_message_id) if delay_message_id
|
138
138
|
end
|
139
139
|
end
|
data/lib/redstream/version.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path("../spec_helper", __dir__)
|
|
3
3
|
RSpec.describe Redstream::Delayer do
|
4
4
|
describe "#run_once" do
|
5
5
|
it "copies expired messages to their target streams" do
|
6
|
-
redis.xadd
|
6
|
+
redis.xadd(Redstream.stream_key_name("target.delay"), { payload: JSON.dump(value: "message") })
|
7
7
|
|
8
8
|
expect(redis.xlen(Redstream.stream_key_name("target"))).to eq(0)
|
9
9
|
|
@@ -14,9 +14,9 @@ RSpec.describe Redstream::Delayer do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "delivers and commit before falling asleep" do
|
17
|
-
redis.xadd
|
17
|
+
redis.xadd(Redstream.stream_key_name("target.delay"), { payload: JSON.dump(value: "message") })
|
18
18
|
sleep 3
|
19
|
-
redis.xadd
|
19
|
+
redis.xadd(Redstream.stream_key_name("target.delay"), { payload: JSON.dump(value: "message") })
|
20
20
|
|
21
21
|
thread = Thread.new do
|
22
22
|
Redstream::Delayer.new(stream_name: "target", delay: 1).run_once
|
@@ -33,7 +33,7 @@ RSpec.describe Redstream::Delayer do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "does not copy not yet expired messages" do
|
36
|
-
redis.xadd
|
36
|
+
redis.xadd(Redstream.stream_key_name("target.delay"), { payload: JSON.dump(value: "message") })
|
37
37
|
|
38
38
|
thread = Thread.new do
|
39
39
|
Redstream::Delayer.new(stream_name: "target", delay: 2).run_once
|
@@ -4,11 +4,11 @@ RSpec.describe Redstream::Trimmer do
|
|
4
4
|
describe "#run_once" do
|
5
5
|
it "trims a stream to the minimum committed id" do
|
6
6
|
ids = Array.new(4) do |i|
|
7
|
-
redis.xadd
|
7
|
+
redis.xadd(Redstream.stream_key_name("default"), { payload: JSON.dump(value: "message#{i}") })
|
8
8
|
end
|
9
9
|
|
10
|
-
redis.set
|
11
|
-
redis.set
|
10
|
+
redis.set(Redstream.offset_key_name(stream_name: "default", consumer_name: "consumer1"), ids[1])
|
11
|
+
redis.set(Redstream.offset_key_name(stream_name: "default", consumer_name: "consumer2"), ids[2])
|
12
12
|
|
13
13
|
trimmer = Redstream::Trimmer.new(
|
14
14
|
interval: 5,
|
data/spec/redstream_spec.rb
CHANGED
@@ -34,7 +34,7 @@ RSpec.describe Redstream do
|
|
34
34
|
it "returns the stream's size" do
|
35
35
|
expect(Redstream.stream_size("products")).to eq(0)
|
36
36
|
|
37
|
-
redis.xadd("redstream:stream:products", key: "value")
|
37
|
+
redis.xadd("redstream:stream:products", { key: "value" })
|
38
38
|
|
39
39
|
expect(Redstream.stream_size("products")).to eq(1)
|
40
40
|
end
|
@@ -44,8 +44,8 @@ RSpec.describe Redstream do
|
|
44
44
|
it "returns the stream's max id" do
|
45
45
|
expect(Redstream.max_stream_id("products")).to be_nil
|
46
46
|
|
47
|
-
_id1 = redis.xadd("redstream:stream:products", key: "value")
|
48
|
-
id2 = redis.xadd("redstream:stream:products", key: "value")
|
47
|
+
_id1 = redis.xadd("redstream:stream:products", { key: "value" })
|
48
|
+
id2 = redis.xadd("redstream:stream:products", { key: "value" })
|
49
49
|
|
50
50
|
expect(Redstream.max_stream_id("products")).to eq(id2)
|
51
51
|
end
|
@@ -55,8 +55,8 @@ RSpec.describe Redstream do
|
|
55
55
|
it "returns the consumer's max id" do
|
56
56
|
expect(Redstream.max_consumer_id(stream_name: "products", consumer_name: "consumer")).to be_nil
|
57
57
|
|
58
|
-
_id1 = redis.xadd("redstream:stream:products", key: "value")
|
59
|
-
id2 = redis.xadd("redstream:stream:products", key: "value")
|
58
|
+
_id1 = redis.xadd("redstream:stream:products", { key: "value" })
|
59
|
+
id2 = redis.xadd("redstream:stream:products", { key: "value" })
|
60
60
|
|
61
61
|
Redstream::Consumer.new(name: "consumer", stream_name: "products").run_once do |messages|
|
62
62
|
# nothing
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
289
289
|
- !ruby/object:Gem::Version
|
290
290
|
version: '0'
|
291
291
|
requirements: []
|
292
|
-
rubygems_version: 3.
|
292
|
+
rubygems_version: 3.2.15
|
293
293
|
signing_key:
|
294
294
|
specification_version: 4
|
295
295
|
summary: Using redis streams to keep your primary database in sync with secondary
|