batchy 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/batchy/batch.rb
CHANGED
@@ -14,6 +14,7 @@ module Batchy
|
|
14
14
|
has_many :children, :primary_key => :id, :foreign_key => :parent_id, :class_name => 'Batchy::Batch'
|
15
15
|
|
16
16
|
serialize :error
|
17
|
+
serialize :backtrace
|
17
18
|
|
18
19
|
state_machine :state, :initial => :new do
|
19
20
|
event :start do
|
@@ -79,6 +80,25 @@ module Batchy
|
|
79
80
|
rel.where("id <> ?", id)
|
80
81
|
end
|
81
82
|
|
83
|
+
# When serializing an exception, the YAML library does not save the
|
84
|
+
# backtrace. To fix this, we're saving both the error and backtrace
|
85
|
+
# when the error is saved
|
86
|
+
def error=(err)
|
87
|
+
write_attribute(:error, err)
|
88
|
+
write_attribute(:backtrace, err.backtrace)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Conversely, the backtrace is added to the error after a read
|
92
|
+
def error
|
93
|
+
err = read_attribute(:error)
|
94
|
+
return err if err.blank?
|
95
|
+
|
96
|
+
backtrace = read_attribute(:backtrace)
|
97
|
+
err.set_backtrace(backtrace)
|
98
|
+
|
99
|
+
err
|
100
|
+
end
|
101
|
+
|
82
102
|
# Is this batch expired
|
83
103
|
def expired?
|
84
104
|
expire_at < DateTime.now && state == 'running'
|
data/lib/batchy/version.rb
CHANGED
@@ -10,7 +10,8 @@ class CreateBatchyBatches < ActiveRecord::Migration
|
|
10
10
|
table.integer :pid # Process ID of the current batch
|
11
11
|
table.string :name # Name of the batch job
|
12
12
|
table.string :guid # Field to be used for unique identification of the calling job
|
13
|
-
table.integer :parent_id
|
13
|
+
table.integer :parent_id # Self-referential ID for identifying parent batches
|
14
|
+
table.text :backtrace # Backtrace for an error, if there is one
|
14
15
|
table.timestamps
|
15
16
|
end
|
16
17
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_record/migration'
|
4
|
+
|
5
|
+
module Batchy
|
6
|
+
class UpgradeGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
extend ActiveRecord::Generators::Migration
|
9
|
+
|
10
|
+
self.source_paths << File.join(File.dirname(__FILE__), 'templates')
|
11
|
+
|
12
|
+
def create_migration_file
|
13
|
+
migration_template 'upgrade_migration.rb', 'db/migrate/add_backtrace_to_batchy.rb'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: batchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
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-04-03 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -149,6 +149,8 @@ files:
|
|
149
149
|
- lib/batchy.rb
|
150
150
|
- lib/generators/batchy/active_record_generator.rb
|
151
151
|
- lib/generators/batchy/templates/migration.rb
|
152
|
+
- lib/generators/batchy/templates/upgrade_migration.rb
|
153
|
+
- lib/generators/batchy/upgrade_generator.rb
|
152
154
|
- lib/tasks/batchy_tasks.rake
|
153
155
|
- MIT-LICENSE
|
154
156
|
- Rakefile
|
@@ -166,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
168
|
requirements:
|
167
169
|
- - ">="
|
168
170
|
- !ruby/object:Gem::Version
|
169
|
-
hash:
|
171
|
+
hash: 4457839131585176911
|
170
172
|
segments:
|
171
173
|
- 0
|
172
174
|
version: "0"
|
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
requirements:
|
176
178
|
- - ">="
|
177
179
|
- !ruby/object:Gem::Version
|
178
|
-
hash:
|
180
|
+
hash: 4457839131585176911
|
179
181
|
segments:
|
180
182
|
- 0
|
181
183
|
version: "0"
|