batchy 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/batchy.rb CHANGED
@@ -76,6 +76,8 @@ module Batchy
76
76
  options = args.extract_options!
77
77
 
78
78
  batch = Batch.create options
79
+ batch.clear_zombies unless batch.guid.nil?
80
+
79
81
  batch.start!
80
82
  return false if batch.ignored?
81
83
  begin
data/lib/batchy/batch.rb CHANGED
@@ -69,6 +69,17 @@ module Batchy
69
69
  duplicate_batches.count > 0
70
70
  end
71
71
 
72
+ # Removes duplicate batches that are stuck in
73
+ # a running state
74
+ def clear_zombies
75
+ duplicate_batches.each do | dup |
76
+ if not dup.process_running?
77
+ dup.error = Batchy::Error.new("Process has died, moving to a finished state")
78
+ dup.finish!
79
+ end
80
+ end
81
+ end
82
+
72
83
  # Find all batches with the same guid that are
73
84
  # running.
74
85
  def duplicate_batches
@@ -85,7 +96,7 @@ module Batchy
85
96
  # when the error is saved
86
97
  def error=(err)
87
98
  write_attribute(:error, err)
88
- write_attribute(:backtrace, err.backtrace)
99
+ write_attribute(:backtrace, err.backtrace) if err.respond_to?(:backtrace)
89
100
  end
90
101
 
91
102
  # Conversely, the backtrace is added to the error after a read
@@ -170,6 +181,14 @@ module Batchy
170
181
  end
171
182
  end
172
183
 
184
+ # Checks to see if the process attached to this
185
+ # batch is active
186
+ def process_running?
187
+ raise Batchy::Error, 'Current host does not match the host running the batch' unless Socket.gethostname == hostname
188
+
189
+ not Sys::ProcTable.ps(pid).blank?
190
+ end
191
+
173
192
  # :nodoc:
174
193
  def run_ensure_callbacks
175
194
  Batchy.configure.global_ensure_callbacks.each do | ec |
@@ -1,3 +1,3 @@
1
1
  module Batchy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: batchy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bob Briski
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-03 00:00:00 Z
13
+ date: 2012-04-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
169
  - - ">="
170
170
  - !ruby/object:Gem::Version
171
- hash: 4457839131585176911
171
+ hash: 1197839351505114963
172
172
  segments:
173
173
  - 0
174
174
  version: "0"
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- hash: 4457839131585176911
180
+ hash: 1197839351505114963
181
181
  segments:
182
182
  - 0
183
183
  version: "0"