stalking 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,7 +56,7 @@ module Stalking
56
56
  end
57
57
  end
58
58
  rescue EOFError, Beanstalk::NotConnected => e
59
- log_error e
59
+ @logger.andand.error e.message
60
60
 
61
61
  sleep 1
62
62
 
@@ -64,7 +64,7 @@ module Stalking
64
64
 
65
65
  retry
66
66
  rescue => e
67
- log_error e
67
+ @logger.andand.error e.message
68
68
 
69
69
  raise e
70
70
  end
@@ -98,7 +98,7 @@ module Stalking
98
98
 
99
99
  @connection
100
100
  rescue Beanstalk::NotConnected => e
101
- log_error e
101
+ @logger.andand.error e.message
102
102
 
103
103
  sleep 1
104
104
 
@@ -112,10 +112,6 @@ module Stalking
112
112
 
113
113
  connect
114
114
  end
115
-
116
- def log_error(e)
117
- @logger.error("Stalking error: #{e.message}") if @logger
118
- end
119
115
  end
120
116
  end
121
117
 
@@ -18,11 +18,13 @@ module Stalking
18
18
  end
19
19
 
20
20
  def enqueue(name, args = {}, options = {})
21
+ @logger.andand.info "Enqueue #{name.inspect} with #{args.inspect} and #{options.inspect}"
22
+
21
23
  # Send the job to a random server.
22
24
 
23
25
  @servers.shuffle.first(@tries).each do |server|
24
26
  begin
25
- Timeout::timeout(@timeout) do
27
+ Timeout::timeout @timeout do
26
28
  @connections[server] ||= Beanstalk::Pool.new([server])
27
29
 
28
30
  enq @connections[server], name, args, options
@@ -34,7 +36,7 @@ module Stalking
34
36
  # Let's try to reconnect and enqueue afterwards.
35
37
 
36
38
  begin
37
- Timeout::timeout(@timeout) do
39
+ Timeout::timeout @timeout do
38
40
  @connections[server] = Beanstalk::Pool.new([server])
39
41
 
40
42
  enq @connections[server], name, args, options
@@ -42,13 +44,15 @@ module Stalking
42
44
 
43
45
  return true
44
46
  rescue Beanstalk::NotConnected, Timeout::Error, StandardError => e
45
- log_error e
47
+ @logger.andand.error e.message
46
48
  end
47
49
  rescue Timeout::Error, StandardError => e
48
- log_error e
50
+ @logger.andand.error e.message
49
51
  end
50
52
  end
51
53
 
54
+ @logger.andand.error "Enqueue #{name.inspect} with #{args.inspect} and #{options.inspect} failed"
55
+
52
56
  # All servers are currently unavailable.
53
57
  # Enqueuing the job has failed.
54
58
 
@@ -65,10 +69,6 @@ module Stalking
65
69
  connection.use name
66
70
  connection.put [name, args].to_json, pri, delay, ttr
67
71
  end
68
-
69
- def log_error(e)
70
- @logger.error("Stalking error: #{e.message}") if @logger
71
- end
72
72
  end
73
73
  end
74
74
 
@@ -1,3 +1,3 @@
1
1
  module Stalking
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/stalking.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require "stalking/version"
3
3
  require "beanstalk-client"
4
4
  require "timeout"
5
+ require "andand"
5
6
  require "json"
6
7
 
7
8
  require "stalking/handlers"
data/stalking.gemspec CHANGED
@@ -20,5 +20,6 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "beanstalk-client"
22
22
  s.add_dependency "json_pure"
23
+ s.add_dependency "andand"
23
24
  end
24
25
 
@@ -199,7 +199,7 @@ class Stalking::ConsumerTest < Test::Unit::TestCase
199
199
 
200
200
  assert_equal [["down"], ["test", { "a" => "b" }]], res
201
201
 
202
- assert_equal ["Stalking error: Beanstalk::NotConnected"], logger.messages
202
+ assert_equal ["Beanstalk::NotConnected"], logger.messages
203
203
  end
204
204
 
205
205
  def test_logger
@@ -80,7 +80,7 @@ class Stalking::ProducerTest < Test::Unit::TestCase
80
80
 
81
81
  producer.enqueue "test", "up" => "true"
82
82
 
83
- assert_equal ["Stalking error: Beanstalk::NotConnected"], logger.messages
83
+ assert_equal ['Enqueue "test" with {"up"=>"true"} and {}', "Beanstalk::NotConnected", 'Enqueue "test" with {"up"=>"true"} and {} failed'], logger.messages
84
84
  end
85
85
  end
86
86
 
@@ -6,6 +6,10 @@ class TestLogger
6
6
  @messages = []
7
7
  end
8
8
 
9
+ def info(msg)
10
+ @messages.push msg
11
+ end
12
+
9
13
  def error(msg)
10
14
  @messages.push msg
11
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stalking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
12
+ date: 2013-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: andand
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: Asynchronous job processing using the beanstalkd queue server with automatic
63
79
  reconnects and failover
64
80
  email: