stalker 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/stalker.rb +7 -1
- data/test/stalker_test.rb +30 -8
- metadata +4 -16
data/README.md
CHANGED
@@ -72,7 +72,7 @@ Error Handling
|
|
72
72
|
|
73
73
|
If you include an `error` block in your jobs definition, that block will be invoked when a worker encounters an error. You might use this to report errors to an external monitoring service:
|
74
74
|
|
75
|
-
error do |e|
|
75
|
+
error do |e, job, args|
|
76
76
|
Exceptional.handle(e)
|
77
77
|
end
|
78
78
|
|
@@ -110,7 +110,7 @@ Meta
|
|
110
110
|
|
111
111
|
Created by Adam Wiggins
|
112
112
|
|
113
|
-
Patches from Jamie Cobbett, Scott Water, Keith Rarick, Mark McGranaghan, Sean Walberg
|
113
|
+
Patches from Jamie Cobbett, Scott Water, Keith Rarick, Mark McGranaghan, Sean Walberg, Adam Pohorecki
|
114
114
|
|
115
115
|
Heavily inspired by [Minion](http://github.com/orionz/minion) by Orion Henry
|
116
116
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/stalker.rb
CHANGED
@@ -96,7 +96,13 @@ module Stalker
|
|
96
96
|
log_error exception_message(e)
|
97
97
|
job.bury rescue nil
|
98
98
|
log_job_end(name, 'failed')
|
99
|
-
|
99
|
+
if error_handler
|
100
|
+
if error_handler.arity == 1
|
101
|
+
error_handler.call(e)
|
102
|
+
else
|
103
|
+
error_handler.call(e, name, args)
|
104
|
+
end
|
105
|
+
end
|
100
106
|
end
|
101
107
|
|
102
108
|
def failed_connection(e)
|
data/test/stalker_test.rb
CHANGED
@@ -14,6 +14,14 @@ class StalkerTest < Test::Unit::TestCase
|
|
14
14
|
$handled = false
|
15
15
|
end
|
16
16
|
|
17
|
+
def with_an_error_handler
|
18
|
+
Stalker.error do |e, job_name, args|
|
19
|
+
$handled = e.class
|
20
|
+
$job_name = job_name
|
21
|
+
$job_args = args
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
test "enqueue and work a job" do
|
18
26
|
val = rand(999999)
|
19
27
|
Stalker.job('my.job') { |args| $result = args['val'] }
|
@@ -24,12 +32,24 @@ class StalkerTest < Test::Unit::TestCase
|
|
24
32
|
end
|
25
33
|
|
26
34
|
test "invoke error handler when defined" do
|
27
|
-
|
28
|
-
Stalker.job('my.job') { fail }
|
29
|
-
Stalker.enqueue('my.job')
|
35
|
+
with_an_error_handler
|
36
|
+
Stalker.job('my.job') { |args| fail }
|
37
|
+
Stalker.enqueue('my.job', :foo => 123)
|
30
38
|
Stalker.prep
|
31
39
|
Stalker.work_one_job
|
32
|
-
|
40
|
+
assert $handled
|
41
|
+
assert_equal 'my.job', $job_name
|
42
|
+
assert_equal({'foo' => 123}, $job_args)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should be compatible with legacy error handlers" do
|
46
|
+
exception = StandardError.new("Oh my, the job has failed!")
|
47
|
+
Stalker.error { |e| $handled = e }
|
48
|
+
Stalker.job('my.job') { |args| raise exception }
|
49
|
+
Stalker.enqueue('my.job', :foo => 123)
|
50
|
+
Stalker.prep
|
51
|
+
Stalker.work_one_job
|
52
|
+
assert_equal exception, $handled
|
33
53
|
end
|
34
54
|
|
35
55
|
test "continue working when error handler not defined" do
|
@@ -41,7 +61,7 @@ class StalkerTest < Test::Unit::TestCase
|
|
41
61
|
end
|
42
62
|
|
43
63
|
test "exception raised one second before beanstalk ttr reached" do
|
44
|
-
|
64
|
+
with_an_error_handler
|
45
65
|
Stalker.job('my.job') { sleep(3); $handled = "didn't time out" }
|
46
66
|
Stalker.enqueue('my.job', {}, :ttr => 2)
|
47
67
|
Stalker.prep
|
@@ -77,13 +97,15 @@ class StalkerTest < Test::Unit::TestCase
|
|
77
97
|
end
|
78
98
|
|
79
99
|
test "before filter invokes error handler when defined" do
|
80
|
-
|
100
|
+
with_an_error_handler
|
81
101
|
Stalker.before { |name| fail }
|
82
102
|
Stalker.job('my.job') { }
|
83
|
-
Stalker.enqueue('my.job')
|
103
|
+
Stalker.enqueue('my.job', :foo => 123)
|
84
104
|
Stalker.prep
|
85
105
|
Stalker.work_one_job
|
86
|
-
|
106
|
+
assert $handled
|
107
|
+
assert_equal 'my.job', $job_name
|
108
|
+
assert_equal({'foo' => 123}, $job_args)
|
87
109
|
end
|
88
110
|
|
89
111
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stalker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 7
|
8
|
-
- 0
|
9
|
-
version: 0.7.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.8.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Adam Wiggins
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-03-11 00:00:00 -08:00
|
18
14
|
default_executable: stalk
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :runtime
|
32
26
|
version_requirements: *id001
|
@@ -38,8 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
35
|
version: "0"
|
44
36
|
type: :runtime
|
45
37
|
version_requirements: *id002
|
@@ -74,21 +66,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
66
|
requirements:
|
75
67
|
- - ">="
|
76
68
|
- !ruby/object:Gem::Version
|
77
|
-
segments:
|
78
|
-
- 0
|
79
69
|
version: "0"
|
80
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
71
|
none: false
|
82
72
|
requirements:
|
83
73
|
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
segments:
|
86
|
-
- 0
|
87
75
|
version: "0"
|
88
76
|
requirements: []
|
89
77
|
|
90
78
|
rubyforge_project: stalker
|
91
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.5.0
|
92
80
|
signing_key:
|
93
81
|
specification_version: 3
|
94
82
|
summary: A job queueing and background workers system using Beanstalkd.
|