schlepper 0.9.1 → 0.10.1
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.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/schlepper/process.rb +34 -16
- data/lib/schlepper/task.rb +8 -0
- data/lib/schlepper/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fa3e185f4b1e3af4ccaff4ad72af1207b4b36e3
|
4
|
+
data.tar.gz: 95a4032864b39ef3f9506764c446b04ad40b40ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3944d556c0c8a83549355e4eb4466dd5e1c9308f458d066ce112521aabb4e4aafdb12129c347599dea8cb194bf52812a8154c32f342866ddb286ae12a719f8c8
|
7
|
+
data.tar.gz: 0a5e9b939b61b8ee2ba5ac5e6511d7923b21fdc0f6343d423e9ff64e17ac7fa5544cc5d8cad03f581693b8e1c2b1dcdaae10c08cfc253e4cdf0fd7949bb2e75a
|
data/README.md
CHANGED
@@ -47,6 +47,14 @@ override:
|
|
47
47
|
class NameOfTask < Schlepper::Task
|
48
48
|
attr_reader :failure_message
|
49
49
|
|
50
|
+
# Signals to the task runner that this task will control its own transaction.
|
51
|
+
# When true the task runner will not open a transaction.
|
52
|
+
# Use with caution.
|
53
|
+
# @return [Boolean]
|
54
|
+
def controls_transaction?
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
50
58
|
# @return [String] A short note on what the purpose of this task is
|
51
59
|
def description
|
52
60
|
<<-DOC.strip_heredoc
|
@@ -82,6 +90,9 @@ of the `run` method. You must return a literal `true` to signal to the task runn
|
|
82
90
|
has completed successfully. Any return value other than `true` will signal to the task runner
|
83
91
|
that this task has not completed successfully, and will not be marked as successful.
|
84
92
|
|
93
|
+
The method `controls_transaction?` is optional. If it returns `true`, the task
|
94
|
+
won't run in a transaction, and returning `false` from `run` won't roll anything back.
|
95
|
+
|
85
96
|
Also take note of the instance variable `@failure_message`. Setting this to something
|
86
97
|
descriptive if your task fails provides meaningful output to the person running the task.
|
87
98
|
|
@@ -103,6 +114,8 @@ Use `rake schlepper:run` to start the task running process. The task running pro
|
|
103
114
|
- Roll back transaction
|
104
115
|
- Display the name of the owner, and @failure\_message if provided
|
105
116
|
|
117
|
+
The transaction steps are skipped if `controls_transaction?` is defined and returns `true`.
|
118
|
+
|
106
119
|
## Development
|
107
120
|
|
108
121
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/schlepper/process.rb
CHANGED
@@ -74,27 +74,23 @@ module Schlepper
|
|
74
74
|
end
|
75
75
|
|
76
76
|
private def process_one klass
|
77
|
-
|
77
|
+
task = klass.new
|
78
78
|
|
79
79
|
puts ''
|
80
|
-
puts "Processing #{klass.name} from #{
|
81
|
-
puts "#{
|
80
|
+
puts "Processing #{klass.name} from #{task.owner}:"
|
81
|
+
puts "#{task.description}"
|
82
82
|
puts ''
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
puts "The resulting failure was: #{runner.failure_message}"
|
94
|
-
else
|
95
|
-
puts "The failure message was not set. Find #{runner.owner} to help investigate"
|
84
|
+
if task.controls_transaction?
|
85
|
+
status = run_task_for task
|
86
|
+
log_error(klass.name, task.failure_message, task.owner) unless status
|
87
|
+
else
|
88
|
+
ActiveRecord::Base.transaction do
|
89
|
+
status = run_task_for task
|
90
|
+
unless status
|
91
|
+
log_error(klass.name, task.failure_message, task.owner)
|
92
|
+
fail ActiveRecord::Rollback
|
96
93
|
end
|
97
|
-
fail ActiveRecord::Rollback
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
@@ -102,5 +98,27 @@ module Schlepper
|
|
102
98
|
puts "Finished #{klass.name}"
|
103
99
|
puts '~~~~~~~~~~~~~~~~~~~~~'
|
104
100
|
end
|
101
|
+
|
102
|
+
private def run_task_for(task)
|
103
|
+
status = task.run
|
104
|
+
|
105
|
+
if status
|
106
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
107
|
+
INSERT INTO schlepper_tasks (version, owner, description, completed_at)
|
108
|
+
VALUES (#{task.version_number}, #{ActiveRecord::Base.sanitize(task.owner)}, #{ActiveRecord::Base.sanitize(task.description)}, #{ActiveRecord::Base.connection.quote(Time.now.to_s(:db))});
|
109
|
+
SQL
|
110
|
+
end
|
111
|
+
|
112
|
+
status
|
113
|
+
end
|
114
|
+
|
115
|
+
private def log_error(name, message, owner)
|
116
|
+
puts "#{name} ran without errors, but was not successful"
|
117
|
+
if message
|
118
|
+
puts "The resulting failure was: #{message}"
|
119
|
+
else
|
120
|
+
puts "The failure message was not set. Find #{owner} to help investigate"
|
121
|
+
end
|
122
|
+
end
|
105
123
|
end
|
106
124
|
end
|
data/lib/schlepper/task.rb
CHANGED
@@ -23,6 +23,14 @@ module Schlepper
|
|
23
23
|
@version_number ||= File.basename(method(:run).source_location.first).scan(/\A(\d{10,})/).first.first
|
24
24
|
end
|
25
25
|
|
26
|
+
# Signals to the task runner that this task will control its own transaction.
|
27
|
+
# When true the task runner will not open a transaction.
|
28
|
+
# Use with caution.
|
29
|
+
# @return [Boolean]
|
30
|
+
def controls_transaction?
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
26
34
|
# @return [String] Short note on the intent of this script
|
27
35
|
# @abstract
|
28
36
|
abstract def description
|
data/lib/schlepper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schlepper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rory O'Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.6.10
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Adds tracking of one off data scripts for Rails.
|