stalker 0.6.1 → 0.7.0

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 +11 -2
  2. data/VERSION +1 -1
  3. data/lib/stalker.rb +11 -0
  4. data/test/stalker_test.rb +38 -0
  5. metadata +4 -4
data/README.md CHANGED
@@ -73,7 +73,16 @@ Error Handling
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
75
  error do |e|
76
- Exceptional.handle(e)
76
+ Exceptional.handle(e)
77
+ end
78
+
79
+ Before filter
80
+ -------------
81
+
82
+ If you wish to run a block of code prior to any job:
83
+
84
+ before do |job|
85
+ puts "About to work #{job}"
77
86
  end
78
87
 
79
88
  Tidbits
@@ -101,7 +110,7 @@ Meta
101
110
 
102
111
  Created by Adam Wiggins
103
112
 
104
- Patches from Jamie Cobbett, Scott Water, Keith Rarick, Mark McGranaghan
113
+ Patches from Jamie Cobbett, Scott Water, Keith Rarick, Mark McGranaghan, Sean Walberg
105
114
 
106
115
  Heavily inspired by [Minion](http://github.com/orionz/minion) by Orion Henry
107
116
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -26,6 +26,11 @@ module Stalker
26
26
  @@handlers[j] = block
27
27
  end
28
28
 
29
+ def before(&block)
30
+ @@before_handlers ||= []
31
+ @@before_handlers << block
32
+ end
33
+
29
34
  def error(&blk)
30
35
  @@error_handler = blk
31
36
  end
@@ -70,6 +75,11 @@ module Stalker
70
75
 
71
76
  begin
72
77
  Timeout::timeout(job.ttr - 1) do
78
+ if defined? @@before_handlers and @@before_handlers.respond_to? :each
79
+ @@before_handlers.each do |block|
80
+ block.call(name)
81
+ end
82
+ end
73
83
  handler.call(args)
74
84
  end
75
85
  rescue Timeout::Error
@@ -161,6 +171,7 @@ module Stalker
161
171
 
162
172
  def clear!
163
173
  @@handlers = nil
174
+ @@before_handlers = nil
164
175
  @@error_handler = nil
165
176
  end
166
177
  end
@@ -48,4 +48,42 @@ class StalkerTest < Test::Unit::TestCase
48
48
  Stalker.work_one_job
49
49
  assert_equal Stalker::JobTimeout, $handled
50
50
  end
51
+
52
+ test "before filter gets run first" do
53
+ Stalker.before { |name| $flag = "i_was_here" }
54
+ Stalker.job('my.job') { |args| $handled = ($flag == 'i_was_here') }
55
+ Stalker.enqueue('my.job')
56
+ Stalker.prep
57
+ Stalker.work_one_job
58
+ assert_equal true, $handled
59
+ end
60
+
61
+ test "before filter passes the name of the job" do
62
+ Stalker.before { |name| $jobname = name }
63
+ Stalker.job('my.job') { true }
64
+ Stalker.enqueue('my.job')
65
+ Stalker.prep
66
+ Stalker.work_one_job
67
+ assert_equal 'my.job', $jobname
68
+ end
69
+
70
+ test "before filter can pass an instance var" do
71
+ Stalker.before { |name| @foo = "hello" }
72
+ Stalker.job('my.job') { |args| $handled = (@foo == "hello") }
73
+ Stalker.enqueue('my.job')
74
+ Stalker.prep
75
+ Stalker.work_one_job
76
+ assert_equal true, $handled
77
+ end
78
+
79
+ test "before filter invokes error handler when defined" do
80
+ Stalker.error { |e| $handled = true }
81
+ Stalker.before { |name| fail }
82
+ Stalker.job('my.job') { }
83
+ Stalker.enqueue('my.job')
84
+ Stalker.prep
85
+ Stalker.work_one_job
86
+ assert_equal true, $handled
87
+ end
88
+
51
89
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Wiggins
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-03 00:00:00 -08:00
17
+ date: 2011-01-20 00:00:00 -08:00
18
18
  default_executable: stalk
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency