redstream 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -3
- data/lib/redstream/model.rb +2 -1
- data/lib/redstream/version.rb +1 -1
- data/spec/redstream/model_spec.rb +33 -35
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6be694edcad63b15c2e7a6630047080556a412fc1b52f874e4f793e8f07f80b9
|
4
|
+
data.tar.gz: f140446d6fbebc97533de509ff622fe32b121cd89af2c5f0cc2b856f5e820e02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b38daa5a07f1761fa47340c4d479b974b30937479a6a73897ad8d8e47c9d45328ef976d20b8a74a7cb0488d35985864d162b3adbb66133e56195cb016b09ab4
|
7
|
+
data.tar.gz: 0b625e0f6fea967e69ba319115dd9bfd727b68aec369a83a0842bb39805b0389ebef33bae5cf2559314d54724a9fd28d5a517ab8cbdc88f14db1ec5a601c12ee
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
|
3
|
+
## v0.1.1
|
4
|
+
* Fix missing queue message in `after_commit on: :destroy`
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
## v0.1.0
|
7
|
+
* No longer queue/delay in `after_save`/`after_commit` if no changes occurred
|
8
|
+
* Added `Redstream.stream_size`
|
data/lib/redstream/model.rb
CHANGED
@@ -32,7 +32,8 @@ module Redstream
|
|
32
32
|
after_save { |object| producer.delay(object) if object.saved_changes.present? }
|
33
33
|
after_touch { |object| producer.delay(object) }
|
34
34
|
after_destroy { |object| producer.delay(object) }
|
35
|
-
after_commit { |object| producer.queue(object) if object.saved_changes.present? }
|
35
|
+
after_commit(on: [:create, :update]) { |object| producer.queue(object) if object.saved_changes.present? }
|
36
|
+
after_commit(on: :destroy) { |object| producer.queue(object) }
|
36
37
|
end
|
37
38
|
|
38
39
|
def redstream_name
|
data/lib/redstream/version.rb
CHANGED
@@ -2,74 +2,72 @@ require File.expand_path("../spec_helper", __dir__)
|
|
2
2
|
|
3
3
|
RSpec.describe Redstream::Model do
|
4
4
|
describe "after_save" do
|
5
|
-
it "adds a delay message
|
6
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))
|
7
|
-
|
8
|
-
time = Time.now
|
5
|
+
it "adds a delay message after_save" do
|
6
|
+
expect { create(:product) }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
it "adds the correct payload for the delay message" do
|
10
|
+
product = create(:product)
|
13
11
|
|
14
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(1)
|
15
12
|
expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").first[1]).to eq("payload" => JSON.dump(product.redstream_payload))
|
16
13
|
end
|
17
14
|
|
18
|
-
it "
|
15
|
+
it "adds a queue message after_save on commit" do
|
16
|
+
expect { create(:product) }.to change { redis.xlen(Redstream.stream_key_name("products")) }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not add a delay message after_save if there are no changes" do
|
19
20
|
product = create(:product)
|
20
21
|
|
21
22
|
expect { product.save }.not_to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
|
22
23
|
end
|
24
|
+
|
25
|
+
it "does not add a queue messages after_save on commit if there are no changes" do
|
26
|
+
product = create(:product)
|
27
|
+
|
28
|
+
expect { product.save }.not_to change { redis.xlen(Redstream.stream_key_name("products")) }
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
describe "after_touch" do
|
26
33
|
it "adds a delay message after touch" do
|
27
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(0)
|
28
|
-
|
29
34
|
product = create(:product)
|
30
35
|
|
31
|
-
|
36
|
+
expect { product.touch }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
|
37
|
+
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
it "sets the correct payload for the delay message" do
|
40
|
+
product = create(:product)
|
41
|
+
product.touch
|
36
42
|
|
37
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(2)
|
38
43
|
expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
|
39
44
|
end
|
45
|
+
|
46
|
+
it "adds a queue message after touch commit" do
|
47
|
+
product = create(:product)
|
48
|
+
|
49
|
+
expect { product.touch }.to change { redis.xlen(Redstream.stream_key_name("products")) }
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
53
|
describe "after_destroy" do
|
43
54
|
it "adds a delay message after destroy" do
|
44
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(0)
|
45
|
-
|
46
55
|
product = create(:product)
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
Timecop.freeze(time) do
|
51
|
-
product.touch
|
52
|
-
end
|
53
|
-
|
54
|
-
expect(redis.xlen(Redstream.stream_key_name("products.delay"))).to eq(2)
|
55
|
-
expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
|
57
|
+
expect { product.destroy }.to change { redis.xlen(Redstream.stream_key_name("products.delay")) }
|
56
58
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "after_commit" do
|
60
|
-
it "adds a queue message after commit" do
|
61
|
-
expect(redis.xlen(Redstream.stream_key_name("products"))).to eq(0)
|
62
59
|
|
60
|
+
it "sets the correct payload for the delay message" do
|
63
61
|
product = create(:product)
|
62
|
+
product.destroy
|
64
63
|
|
65
|
-
expect(redis.
|
66
|
-
expect(redis.xrange(Redstream.stream_key_name("products"), "-", "+").first[1]).to eq("payload" => JSON.dump(product.redstream_payload))
|
64
|
+
expect(redis.xrange(Redstream.stream_key_name("products.delay"), "-", "+").last[1]).to eq("payload" => JSON.dump(product.redstream_payload))
|
67
65
|
end
|
68
66
|
|
69
|
-
it "
|
67
|
+
it "adds a queue messages after destroy on commit" do
|
70
68
|
product = create(:product)
|
71
69
|
|
72
|
-
expect { product.
|
70
|
+
expect { product.destroy }.to change { redis.xlen(Redstream.stream_key_name("products")) }.by(1)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
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.1.
|
4
|
+
version: 0.1.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:
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -288,8 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
288
|
- !ruby/object:Gem::Version
|
289
289
|
version: '0'
|
290
290
|
requirements: []
|
291
|
-
|
292
|
-
rubygems_version: 2.7.3
|
291
|
+
rubygems_version: 3.0.3
|
293
292
|
signing_key:
|
294
293
|
specification_version: 4
|
295
294
|
summary: Using redis streams to keep your primary database in sync with secondary
|