simple_queues 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2009 François Beausoleil (francois@teksol.info)
1
+ Copyright (c) 2011 François Beausoleil (francois@teksol.info)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.textile CHANGED
@@ -59,7 +59,7 @@ h2. LICENSE
59
59
 
60
60
  (The MIT License)
61
61
 
62
- Copyright (c) 2008-2009 François Beausoleil (francois@teksol.info)
62
+ Copyright (c) 2011 François Beausoleil (francois@teksol.info)
63
63
 
64
64
  Permission is hereby granted, free of charge, to any person obtaining
65
65
  a copy of this software and associated documentation files (the
@@ -66,7 +66,7 @@ module SimpleQueues
66
66
  timeout = args.shift
67
67
  raise ArgumentError, "Timeout must not be nil" if timeout.nil? || timeout.to_s.empty?
68
68
 
69
- queue, result = @redis.blpop(*@queues.keys, timeout.to_i)
69
+ queue, result = @redis.blpop(*[@queues.keys, timeout.to_i].flatten)
70
70
  @queues.fetch(queue).call(deserialize(result)) if queue
71
71
  queue
72
72
  when 2
@@ -1,3 +1,3 @@
1
1
  module SimpleQueues
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleQueues::Redis, "multiple dequeue" do
4
+ let :queue do
5
+ SimpleQueues::Redis.new
6
+ end
7
+
8
+ let :redis do
9
+ Redis.new
10
+ end
11
+
12
+ before(:each) do
13
+ redis.flushdb
14
+ end
15
+
16
+ it "should accept setting up a dequeue block" do
17
+ lambda do
18
+ queue.on_dequeue(:pages_to_crawl) {|message| message}
19
+ end.should_not raise_error
20
+ end
21
+
22
+ it "should accept setting up multiple dequeue block" do
23
+ lambda do
24
+ queue.on_dequeue(:pages_to_crawl) {|message| message}
25
+ queue.on_dequeue(:pages_to_analyze) {|message| message}
26
+ end.should_not raise_error
27
+ end
28
+
29
+ context "#dequeue_with_timeout" do
30
+ it "should return the queue name when a message was dequeued" do
31
+ queue.on_dequeue(:a) {|message| message}
32
+ queue.on_dequeue(:b) {|message| raise "not here"}
33
+ queue.enqueue(:a, :sent_to => "a")
34
+ queue.dequeue_with_timeout(1).should == "a"
35
+ end
36
+
37
+ it "should return nil when no queues returned anything" do
38
+ queue.on_dequeue(:a) {|message| raise "not here"}
39
+ queue.dequeue_with_timeout(1).should be_nil
40
+ end
41
+
42
+ it "should call into the correct block" do
43
+ a, b = [], []
44
+ queue.on_dequeue(:a) {|message| a << message}
45
+ queue.on_dequeue(:b) {|message| b << message}
46
+
47
+ queue.enqueue(:a, "sent_to" => "a", "serial" => 1)
48
+ queue.enqueue(:b, "sent_to" => "b", "serial" => 1)
49
+ queue.enqueue(:a, "sent_to" => "a", "serial" => 2)
50
+ while queue.dequeue_with_timeout(1)
51
+ # NOP
52
+ end
53
+
54
+ a.should == [{"sent_to" => "a", "serial" => 1}, {"sent_to" => "a", "serial" => 2}]
55
+ b.should == [{"sent_to" => "b", "serial" => 1}]
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_queues
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Fran\xC3\xA7ois Beausoleil"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-22 00:00:00 -04:00
13
+ date: 2011-03-24 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -102,6 +102,7 @@ files:
102
102
  - simple_queues.gemspec
103
103
  - spec/dequeueing_spec.rb
104
104
  - spec/enqueueing_spec.rb
105
+ - spec/multi_dequeue_spec.rb
105
106
  - spec/redis_integration_spec.rb
106
107
  - spec/spec_helper.rb
107
108
  has_rdoc: true
@@ -135,5 +136,6 @@ summary: Simple enqueue/dequeue API for working with queues
135
136
  test_files:
136
137
  - spec/dequeueing_spec.rb
137
138
  - spec/enqueueing_spec.rb
139
+ - spec/multi_dequeue_spec.rb
138
140
  - spec/redis_integration_spec.rb
139
141
  - spec/spec_helper.rb