pubsubstub 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13fa1f1bf8d271516e2ed2389138bf55184d8b13
4
- data.tar.gz: dd1bfc72703d76dc3f6a826bd8b69121efaf1a42
3
+ metadata.gz: 47ff717bde3d2e41574d94a5f95e7a01a086c425
4
+ data.tar.gz: d14af107a0b1be58b2afa83f2a221def5d2a436c
5
5
  SHA512:
6
- metadata.gz: d3948cd0bbbc474de69185969dd120135941a16ecc4eb8c24fe508f80f83130a3b3f6faf4d0a7c6845f1050580222b059bb0581630d4bb4f09916593c0c9dd82
7
- data.tar.gz: 03fe2195a09f6c5bf6cb275399e0f2a447a609c4241e355f3ca7b732edb7d0307157bcb17aee95d89bba99126b4a3c6aa914811d80a6dbc7f436cb5a9a466154
6
+ metadata.gz: 38de78410010ea79af53323418bc7804b47b3b07a3900de2199f7692209b3e16b5e4e317ad48b275dce723c68ebf780bc95e605fae2eda6e7b9a36e5ae5d8ab6
7
+ data.tar.gz: 0911311b184fce34bf5d3845ebccb9a59e05a8a4ae878fd741b4f656db0bf665c4bd5130446b01257a56fecc1520cab9eb2ecd2ce355165cec899db43d2f5645
@@ -1,5 +1,8 @@
1
1
  module Pubsubstub
2
2
  class RedisPubSub
3
+ EVENT_SCORE_THRESHOLD = 1000
4
+ EXPIRE_THRESHOLD = 24 * 60 * 60
5
+
3
6
  def initialize(channel_name)
4
7
  @channel_name = channel_name
5
8
  end
@@ -38,8 +41,13 @@ module Pubsubstub
38
41
 
39
42
  class << self
40
43
  def publish(channel_name, event)
41
- blocking_redis.publish("#{channel_name}.pubsub", event.to_json)
42
- blocking_redis.zadd("#{channel_name}.scrollback", event.id, event.to_json)
44
+ scrollback = "#{channel_name}.scrollback"
45
+ blocking_redis.pipelined do
46
+ blocking_redis.publish("#{channel_name}.pubsub", event.to_json)
47
+ blocking_redis.zadd(scrollback, event.id, event.to_json)
48
+ blocking_redis.zremrangebyrank(scrollback, 0, -EVENT_SCORE_THRESHOLD)
49
+ blocking_redis.expire(scrollback, EXPIRE_THRESHOLD)
50
+ end
43
51
  end
44
52
 
45
53
  def sub
@@ -1,3 +1,3 @@
1
1
  module Pubsubstub
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -9,14 +9,30 @@ describe Pubsubstub::RedisPubSub do
9
9
  let(:redis) { double('redis') }
10
10
  let(:event) { double('Event', to_json: "event_data", id: 1234) }
11
11
  before {
12
- allow(subject).to receive(:blocking_redis) { redis }
12
+ allow(redis).to receive(:pipelined).and_yield
13
13
  }
14
14
 
15
15
  it "publishes the event to a redis channel and adds it to the scrollback" do
16
+ allow(subject).to receive(:blocking_redis) { redis }
16
17
  expect(redis).to receive(:publish).with("test.pubsub", event.to_json)
17
18
  expect(redis).to receive(:zadd).with("test.scrollback", event.id, event.to_json)
19
+ expect(redis).to receive(:zremrangebyrank).with("test.scrollback", 0, -1000)
20
+ expect(redis).to receive(:expire).with("test.scrollback", Pubsubstub::RedisPubSub::EXPIRE_THRESHOLD)
18
21
  subject.publish("test", event)
19
22
  end
23
+
24
+ it "truncates the scrollback" do
25
+ count = Pubsubstub::RedisPubSub::EVENT_SCORE_THRESHOLD
26
+ (1...count).each do |id|
27
+ event = double(to_json: "event_data #{id}", id: id)
28
+ subject.publish('test', event)
29
+ end
30
+ expect(subject.blocking_redis.zcard("test.scrollback")).to eq(count - 1)
31
+
32
+ event = double(to_json: "event_data N", id: count)
33
+ subject.publish('test', event)
34
+ expect(subject.blocking_redis.zcard("test.scrollback")).to eq(count - 1)
35
+ end
20
36
  end
21
37
  end
22
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsubstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Malette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra