super-poller 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- class SuperPoller::QueueItterator
1
+ class SuperPoller::QueueIterator
2
2
  def initialize(queue)
3
3
  @queue = queue
4
4
  end
@@ -1,4 +1,5 @@
1
1
  require "starling"
2
+ require "multi_json"
2
3
 
3
4
  class SuperPoller::StarlingQueue
4
5
  def initialize(queue_name, *args)
@@ -7,15 +8,15 @@ class SuperPoller::StarlingQueue
7
8
  end
8
9
 
9
10
  def pop
10
- @queue.get(@queue_name)
11
+ coerce @queue.get(@queue_name, true)
11
12
  end
12
13
 
13
- def push(v)
14
- @queue.set(@queue_name, v)
14
+ def push(v, raw = false)
15
+ @queue.set(@queue_name, v, 0, raw)
15
16
  end
16
17
 
17
18
  def fetch
18
- @queue.fetch(@queue_name)
19
+ coerce @queue.fetch(@queue_name, true)
19
20
  end
20
21
 
21
22
  def length
@@ -40,4 +41,13 @@ class SuperPoller::StarlingQueue
40
41
  raise
41
42
  end
42
43
  end
44
+
45
+ protected
46
+ def coerce(message)
47
+ if message.start_with?('{')
48
+ MultiJson.decode(message)
49
+ else
50
+ Marshal.load(message)
51
+ end
52
+ end
43
53
  end
data/lib/super_poller.rb CHANGED
@@ -8,7 +8,7 @@ module SuperPoller
8
8
  autoload :AggregatingErrorLogger, "super_poller/aggregating_error_logger"
9
9
  autoload :NoneBlockingPoller, "super_poller/none_blocking_poller"
10
10
  autoload :QueueUrl, "super_poller/queue_url"
11
- autoload :QueueItterator, "super_poller/queue_itterator"
11
+ autoload :QueueIterator, "super_poller/queue_iterator"
12
12
  autoload :Stats, "super_poller/stats"
13
13
  autoload :RetryWrapper, "super_poller/retry_wrapper"
14
14
  end
@@ -27,6 +27,12 @@ class StarlingQueueTest < Test::Unit::TestCase
27
27
  assert_equal "second", queue.pop
28
28
  end
29
29
 
30
+ should "handle JSON messages" do
31
+ queue = StarlingQueue.new("TEST_QUEUE", ["localhost:#{STARLING_PORT}"])
32
+ queue.push('{"foo":"bar"}', raw = true)
33
+ assert_equal({'foo' => 'bar'}, queue.pop)
34
+ end
35
+
30
36
  should 'empty a queue' do
31
37
  queue = StarlingQueue.new("TEST_QUEUE", ["localhost:#{STARLING_PORT}"])
32
38
  queue.push("first")
metadata CHANGED
@@ -1,33 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: super-poller
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 3
9
- version: 0.2.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Tom Lea
13
9
  - George Brocklehurst
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2010-07-27 00:00:00 +01:00
19
- default_executable:
20
- dependencies: []
21
-
13
+ date: 2012-05-23 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: multi_json
17
+ requirement: &70231121376020 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70231121376020
22
26
  description: Small modular library for dealing with queues and pollers.
23
27
  email: contrib@tomlea.co.uk
24
- executables:
28
+ executables:
25
29
  - queue
26
30
  extensions: []
27
-
28
31
  extra_rdoc_files: []
29
-
30
- files:
32
+ files:
31
33
  - bin/queue
32
34
  - bin/scripts/queue_choose
33
35
  - bin/scripts/queue_copy
@@ -42,7 +44,7 @@ files:
42
44
  - lib/super_poller/handler.rb
43
45
  - lib/super_poller/none_blocking_poller.rb
44
46
  - lib/super_poller/poller.rb
45
- - lib/super_poller/queue_itterator.rb
47
+ - lib/super_poller/queue_iterator.rb
46
48
  - lib/super_poller/queue_url.rb
47
49
  - lib/super_poller/retry_wrapper.rb
48
50
  - lib/super_poller/router.rb
@@ -60,35 +62,28 @@ files:
60
62
  - test/starling_queue_test.rb
61
63
  - test/test_helper.rb
62
64
  - Rakefile
63
- has_rdoc: true
64
65
  homepage: http://tomlea.co.uk/
65
66
  licenses: []
66
-
67
67
  post_install_message:
68
68
  rdoc_options: []
69
-
70
- require_paths:
69
+ require_paths:
71
70
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
- version: "0"
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
86
83
  requirements: []
87
-
88
84
  rubyforge_project:
89
- rubygems_version: 1.3.6
85
+ rubygems_version: 1.8.15
90
86
  signing_key:
91
87
  specification_version: 3
92
88
  summary: Tools for dealing with queues.
93
89
  test_files: []
94
-