batchy 0.0.4 → 0.0.5
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.
- data/README.rdoc +1 -3
- data/lib/batchy.rb +29 -0
- data/lib/batchy/batch.rb +6 -3
- data/lib/batchy/version.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -20,9 +20,7 @@ If you're using Rails, you can generate a migration with
|
|
20
20
|
$ rails generate batchy:active_record
|
21
21
|
$ rake db:migrate
|
22
22
|
|
23
|
-
==
|
24
|
-
|
25
|
-
=== Configuration
|
23
|
+
== Configuration
|
26
24
|
|
27
25
|
For a full list of configuration options, check the documentation.
|
28
26
|
|
data/lib/batchy.rb
CHANGED
@@ -54,6 +54,11 @@ module Batchy
|
|
54
54
|
@configuration = nil
|
55
55
|
end
|
56
56
|
|
57
|
+
# Get the current batch
|
58
|
+
def current
|
59
|
+
@current ||= nil
|
60
|
+
end
|
61
|
+
|
57
62
|
# Sets the logger for batchy
|
58
63
|
def logger
|
59
64
|
@logger ||= Logger.new(STDOUT)
|
@@ -74,11 +79,35 @@ module Batchy
|
|
74
79
|
batch.start!
|
75
80
|
return false if batch.ignored?
|
76
81
|
begin
|
82
|
+
# Set the proclist process name
|
83
|
+
previous_name = $0
|
84
|
+
$0 = batch.name if Batchy.configure.name_process
|
85
|
+
|
86
|
+
# Set parent if there is an outer batch
|
87
|
+
if Batchy.current
|
88
|
+
batch.parent = Batchy.current
|
89
|
+
end
|
90
|
+
|
91
|
+
# Set current batch
|
92
|
+
@current = batch
|
93
|
+
|
94
|
+
# Save everything before yielding
|
95
|
+
batch.save!
|
96
|
+
|
77
97
|
yield batch
|
78
98
|
rescue Exception => e
|
79
99
|
batch.error = "{#{e.message}\n#{e.backtrace.join('\n')}"
|
80
100
|
ensure
|
81
101
|
batch.finish!
|
102
|
+
|
103
|
+
# Set current batch to parent (or nil if no parent)
|
104
|
+
@current = batch.parent
|
105
|
+
|
106
|
+
# Set proclist process name back
|
107
|
+
$0 = previous_name
|
82
108
|
end
|
83
109
|
end
|
110
|
+
|
111
|
+
class Error < StandardError
|
112
|
+
end
|
84
113
|
end
|
data/lib/batchy/batch.rb
CHANGED
@@ -10,6 +10,8 @@ module Batchy
|
|
10
10
|
attr_reader :ignore_callbacks
|
11
11
|
|
12
12
|
validates_presence_of :name
|
13
|
+
belongs_to :parent, :class_name => 'Batchy::Batch', :primary_key => :id, :foreign_key => :batch_id
|
14
|
+
has_many :children, :primary_key => :id, :foreign_key => :batch_id, :class_name => 'Batchy::Batch'
|
13
15
|
|
14
16
|
state_machine :state, :initial => :new do
|
15
17
|
event :start do
|
@@ -20,9 +22,6 @@ module Batchy
|
|
20
22
|
batch.started_at = DateTime.now
|
21
23
|
batch.pid = Process.pid
|
22
24
|
batch.save!
|
23
|
-
|
24
|
-
# Set the proclist process name
|
25
|
-
$0 = batch.name if Batchy.configure.name_process
|
26
25
|
end
|
27
26
|
|
28
27
|
# Ignored
|
@@ -63,12 +62,16 @@ module Batchy
|
|
63
62
|
|
64
63
|
# Is there batch with the same guid already running?
|
65
64
|
def already_running
|
65
|
+
return false if guid.nil?
|
66
|
+
|
66
67
|
duplicate_batches.count > 0
|
67
68
|
end
|
68
69
|
|
69
70
|
# Find all batches with the same guid that are
|
70
71
|
# running.
|
71
72
|
def duplicate_batches
|
73
|
+
raise Batchy::Error, "Can not check for duplicate batches on nil guid" if guid.nil?
|
74
|
+
|
72
75
|
rel = self.class.where(:guid => guid, :state => "running")
|
73
76
|
return rel if new_record?
|
74
77
|
|
data/lib/batchy/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: batchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
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-03-
|
13
|
+
date: 2012-03-27 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -166,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
166
|
requirements:
|
167
167
|
- - ">="
|
168
168
|
- !ruby/object:Gem::Version
|
169
|
-
hash: -
|
169
|
+
hash: -791703872644977809
|
170
170
|
segments:
|
171
171
|
- 0
|
172
172
|
version: "0"
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
requirements:
|
176
176
|
- - ">="
|
177
177
|
- !ruby/object:Gem::Version
|
178
|
-
hash: -
|
178
|
+
hash: -791703872644977809
|
179
179
|
segments:
|
180
180
|
- 0
|
181
181
|
version: "0"
|