stalker 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +10 -1
  2. data/VERSION +1 -1
  3. data/lib/stalker.rb +18 -4
  4. data/test/stalker_test.rb +20 -2
  5. metadata +4 -4
data/README.md CHANGED
@@ -67,6 +67,15 @@ In a production environment you may run one or more high-priority workers (limit
67
67
  $ for i in 1 2; do stalk jobs.rb email.send > log/urgent-worker.log 2>&1; end
68
68
  $ for i in 1 2 3 4; do stalk jobs.rb > log/worker.log 2>&1; end
69
69
 
70
+ Error Handling
71
+ -------------
72
+
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
+
75
+ error do |e|
76
+ Exceptional.handle(e)
77
+ end
78
+
70
79
  Tidbits
71
80
  -------
72
81
 
@@ -92,7 +101,7 @@ Meta
92
101
 
93
102
  Created by Adam Wiggins
94
103
 
95
- Patches from Jamie Cobbett and Scott Water
104
+ Patches from Jamie Cobbett, Scott Water, Keith Rarick, Mark McGranaghan
96
105
 
97
106
  Heavily inspired by [Minion](http://github.com/orionz/minion) by Orion Henry
98
107
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -20,6 +20,10 @@ module Stalker
20
20
  @@handlers[j] = block
21
21
  end
22
22
 
23
+ def error(&blk)
24
+ @@error_handler = blk
25
+ end
26
+
23
27
  class NoJobsDefined < RuntimeError; end
24
28
  class NoSuchJob < RuntimeError; end
25
29
 
@@ -62,15 +66,16 @@ module Stalker
62
66
  rescue SystemExit
63
67
  raise
64
68
  rescue => e
65
- STDERR.puts exception_message(e)
69
+ log_error exception_message(e)
66
70
  job.bury rescue nil
67
71
  log_job_end(name, 'failed')
72
+ error_handler.call(e) if error_handler
68
73
  end
69
74
 
70
75
  def failed_connection(e)
71
- STDERR.puts exception_message(e)
72
- STDERR.puts "*** Failed connection to #{beanstalk_url}"
73
- STDERR.puts "*** Check that beanstalkd is running (or set a different BEANSTALK_URL)"
76
+ log_error exception_message(e)
77
+ log_error "*** Failed connection to #{beanstalk_url}"
78
+ log_error "*** Check that beanstalkd is running (or set a different BEANSTALK_URL)"
74
79
  exit 1
75
80
  end
76
81
 
@@ -97,6 +102,10 @@ module Stalker
97
102
  puts "[#{Time.now}] #{msg}"
98
103
  end
99
104
 
105
+ def log_error(msg)
106
+ STDERR.puts msg
107
+ end
108
+
100
109
  def beanstalk
101
110
  @@beanstalk ||= Beanstalk::Pool.new([ beanstalk_host_and_port ])
102
111
  end
@@ -128,7 +137,12 @@ module Stalker
128
137
  @@handlers.keys
129
138
  end
130
139
 
140
+ def error_handler
141
+ @@error_handler
142
+ end
143
+
131
144
  def clear!
132
145
  @@handlers = nil
146
+ @@error_handler = nil
133
147
  end
134
148
  end
@@ -3,14 +3,15 @@ require 'contest'
3
3
  require 'mocha'
4
4
 
5
5
  module Stalker
6
- def log(msg)
7
- end
6
+ def log(msg); end
7
+ def log_error(msg); end
8
8
  end
9
9
 
10
10
  class StalkerTest < Test::Unit::TestCase
11
11
  setup do
12
12
  Stalker.clear!
13
13
  $result = -1
14
+ $handled = false
14
15
  end
15
16
 
16
17
  test "enqueue and work a job" do
@@ -21,4 +22,21 @@ class StalkerTest < Test::Unit::TestCase
21
22
  Stalker.work_one_job
22
23
  assert_equal val, $result
23
24
  end
25
+
26
+ test "invoke error handler when defined" do
27
+ Stalker.error { |e| $handled = true }
28
+ Stalker.job('my.job') { fail }
29
+ Stalker.enqueue('my.job')
30
+ Stalker.prep
31
+ Stalker.work_one_job
32
+ assert_equal true, $handled
33
+ end
34
+
35
+ test "continue working when error handler not defined" do
36
+ Stalker.job('my.job') { fail }
37
+ Stalker.enqueue('my.job')
38
+ Stalker.prep
39
+ Stalker.work_one_job
40
+ assert_equal false, $handled
41
+ end
24
42
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stalker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Wiggins
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-29 00:00:00 -07:00
18
+ date: 2010-08-05 00:00:00 -07:00
19
19
  default_executable: stalk
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency