stalking 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,61 +30,37 @@ module Stalking
30
30
  private
31
31
 
32
32
  def work
33
- setup
33
+ loop do
34
+ job = connection.reserve
34
35
 
35
- begin
36
- loop do
37
- job = connection.reserve
36
+ name, args = JSON.parse(job.body)
38
37
 
39
- exit if @quit
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
- busy do
42
- name, args = JSON.parse(job.body)
43
+ handler.call args
43
44
 
44
- if handler = @handlers.job_handlers[name]
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
- reconnect
69
-
70
- retry
54
+ job.delete
71
55
  end
72
- end
73
-
74
- def setup
75
- trap "QUIT" do
76
- exit unless @busy
56
+ rescue Beanstalk::NotConnected => e
57
+ log_error e
77
58
 
78
- @quit = true
79
- end
80
- end
59
+ sleep 1
81
60
 
82
- def busy
83
- @busy = true
61
+ reconnect
84
62
 
85
- yield
86
- ensure
87
- @busy = false
63
+ retry
88
64
  end
89
65
 
90
66
  def connect
@@ -1,3 +1,3 @@
1
1
  module Stalking
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
 
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: