batchy 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,55 +69,68 @@ module Batchy
69
69
  @logger = logger
70
70
  end
71
71
 
72
+ def create_batch options
73
+ ignore_block = options[:on_ignore] ? options[:on_ignore] : nil
74
+ ensure_block = options[:on_ensure] ? options[:on_ensure] : nil
75
+ options.delete(:on_ignore) if options[:on_ignore]
76
+ options.delete(:on_ensure) if options[:on_ensure]
77
+
78
+ batch = Batch.create options
79
+ batch.on_ignore ignore_block unless ignore_block.nil?
80
+ batch.on_ensure ensure_block unless ensure_block.nil?
81
+ return batch
82
+ end
83
+
72
84
  # The main entry point for batchy. It wraps code in a batchy
73
85
  # block. Batchy handles errors, logging and allows for
74
86
  # callbacks.
75
87
  def run *args
76
88
  options = args.extract_options!
89
+ batch = create_batch options
77
90
 
78
- batch = Batch.create options
79
91
  batch.clear_zombies unless batch.guid.nil?
80
-
81
92
  batch.start!
82
- return false if batch.ignored?
83
- begin
84
- # Set the proclist process name
85
- previous_name = $0
86
- process_name = [Batchy.configure.process_name_prefix, batch.name].join(" ")
87
- $0 = process_name if Batchy.configure.name_process
88
-
89
- # Set parent if there is an outer batch
90
- if Batchy.current
91
- batch.parent = Batchy.current
92
- end
93
93
 
94
- # Set current batch
95
- @current = batch
96
-
97
- # Save everything before yielding
98
- batch.save!
99
-
100
- yield batch
101
-
102
- batch.run_success_callbacks
103
- rescue Exception => e
104
- batch.error = e
105
-
106
- batch.run_failure_callbacks
107
- ensure
108
- batch.finished_at = DateTime.now
109
- batch.finish!
110
-
111
- batch.run_ensure_callbacks
112
-
113
- # Set current batch to parent (or nil if no parent)
114
- @current = batch.parent
115
-
116
- # Set proclist process name back
117
- $0 = previous_name
94
+ unless batch.ignored?
95
+ begin
96
+ # Set the proclist process name
97
+ previous_name = $0
98
+ process_name = [Batchy.configure.process_name_prefix, batch.name].join(" ")
99
+ $0 = process_name if Batchy.configure.name_process
100
+
101
+ # Set parent if there is an outer batch
102
+ if Batchy.current
103
+ batch.parent = Batchy.current
104
+ end
105
+
106
+ # Set current batch
107
+ @current = batch
108
+
109
+ # Save everything before yielding
110
+ batch.save!
111
+
112
+ yield batch
113
+
114
+ batch.run_success_callbacks
115
+ rescue Exception => e
116
+ batch.error = e
117
+
118
+ batch.run_failure_callbacks
119
+ ensure
120
+ batch.finished_at = DateTime.now
121
+ batch.finish!
122
+
123
+ batch.run_ensure_callbacks
124
+
125
+ # Set current batch to parent (or nil if no parent)
126
+ @current = batch.parent
127
+
128
+ # Set proclist process name back
129
+ $0 = previous_name
130
+ end
118
131
  end
119
132
  end
120
133
 
121
134
  class Error < StandardError
122
135
  end
123
- end
136
+ end
@@ -93,7 +93,6 @@ module Batchy
93
93
  options.reverse_merge! :limit_to_current_host => false
94
94
 
95
95
  raise Batchy::Error, "Can not check for duplicate batches on nil guid" if guid.nil?
96
-
97
96
  rel = self.class.where(:guid => guid, :state => "running")
98
97
 
99
98
  if options[:limit_to_current_host]
@@ -252,4 +251,4 @@ module Batchy
252
251
  @ignore_callbacks = []
253
252
  end
254
253
  end
255
- end
254
+ end
@@ -1,3 +1,3 @@
1
1
  module Batchy
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2
5
+ version: 0.2.3
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-30 00:00:00 Z
13
+ date: 2012-05-02 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: -1782560018282016053
171
+ hash: -707801613138086114
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: -1782560018282016053
180
+ hash: -707801613138086114
181
181
  segments:
182
182
  - 0
183
183
  version: "0"