stalking 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stalking/consumer.rb +19 -43
- data/lib/stalking/version.rb +1 -1
- data/test/stalking/consumer_test.rb +4 -4
- metadata +1 -1
data/lib/stalking/consumer.rb
CHANGED
@@ -30,61 +30,37 @@ module Stalking
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def work
|
33
|
-
|
33
|
+
loop do
|
34
|
+
job = connection.reserve
|
34
35
|
|
35
|
-
|
36
|
-
loop do
|
37
|
-
job = connection.reserve
|
36
|
+
name, args = JSON.parse(job.body)
|
38
37
|
|
39
|
-
|
38
|
+
if handler = @handlers.job_handlers[name]
|
39
|
+
begin
|
40
|
+
Timeout::timeout(job.ttr - 1) do
|
41
|
+
handle @handlers.before_handlers, name, args
|
40
42
|
|
41
|
-
|
42
|
-
name, args = JSON.parse(job.body)
|
43
|
+
handler.call args
|
43
44
|
|
44
|
-
|
45
|
-
begin
|
46
|
-
Timeout::timeout(job.ttr - 1) do
|
47
|
-
handle @handlers.before_handlers, name, args
|
48
|
-
|
49
|
-
handler.call args
|
50
|
-
|
51
|
-
handle @handlers.after_handlers, name, args
|
52
|
-
end
|
53
|
-
rescue Beanstalk::NotConnected => e
|
54
|
-
raise e # Re-raise
|
55
|
-
rescue Timeout::Error, StandardError => e
|
56
|
-
handle_error e, name, args
|
57
|
-
end
|
45
|
+
handle @handlers.after_handlers, name, args
|
58
46
|
end
|
47
|
+
rescue Beanstalk::NotConnected => e
|
48
|
+
raise e # Re-raise
|
49
|
+
rescue Timeout::Error, StandardError => e
|
50
|
+
handle_error e, name, args
|
59
51
|
end
|
60
|
-
|
61
|
-
job.delete
|
62
52
|
end
|
63
|
-
rescue Beanstalk::NotConnected => e
|
64
|
-
log_error e
|
65
|
-
|
66
|
-
sleep 1
|
67
53
|
|
68
|
-
|
69
|
-
|
70
|
-
retry
|
54
|
+
job.delete
|
71
55
|
end
|
72
|
-
|
73
|
-
|
74
|
-
def setup
|
75
|
-
trap "QUIT" do
|
76
|
-
exit unless @busy
|
56
|
+
rescue Beanstalk::NotConnected => e
|
57
|
+
log_error e
|
77
58
|
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
59
|
+
sleep 1
|
81
60
|
|
82
|
-
|
83
|
-
@busy = true
|
61
|
+
reconnect
|
84
62
|
|
85
|
-
|
86
|
-
ensure
|
87
|
-
@busy = false
|
63
|
+
retry
|
88
64
|
end
|
89
65
|
|
90
66
|
def connect
|
data/lib/stalking/version.rb
CHANGED
@@ -96,6 +96,10 @@ class Stalking::ConsumerTest < Test::Unit::TestCase
|
|
96
96
|
assert_equal ["test", { "a" => "b" }], res
|
97
97
|
end
|
98
98
|
|
99
|
+
def test_watch
|
100
|
+
# Already tested
|
101
|
+
end
|
102
|
+
|
99
103
|
def test_work
|
100
104
|
Stalking::Producer.new.enqueue "test1", "a" => "b"
|
101
105
|
Stalking::Producer.new.enqueue "test2", "a" => "b"
|
@@ -124,10 +128,6 @@ class Stalking::ConsumerTest < Test::Unit::TestCase
|
|
124
128
|
assert_equal ["test1", "test2", "test3"], res
|
125
129
|
end
|
126
130
|
|
127
|
-
def test_quit
|
128
|
-
raise NotImplementedError
|
129
|
-
end
|
130
|
-
|
131
131
|
def test_job_not_deleted
|
132
132
|
Stalking::Producer.new.enqueue "test", "a" => "b"
|
133
133
|
|