data_miner 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -0
- data/Gemfile +1 -0
- data/data_miner.gemspec +0 -1
- data/lib/data_miner.rb +2 -2
- data/lib/data_miner/active_record_class_methods.rb +1 -2
- data/lib/data_miner/run.rb +14 -12
- data/lib/data_miner/script.rb +5 -3
- data/lib/data_miner/step/import.rb +1 -1
- data/lib/data_miner/step/process.rb +1 -1
- data/lib/data_miner/step/tap.rb +1 -1
- data/lib/data_miner/version.rb +1 -1
- data/test/test_safety.rb +3 -0
- metadata +2 -18
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
2.1.0 / 2012-05-10
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* Don't use "perform" as a class or instance method name - it can interfere with Resque or Sidekiq.
|
6
|
+
* Don't lock DataMiner::Run#perform. Provide instructions for how people can do this manually.
|
7
|
+
|
8
|
+
* Bug fixes
|
9
|
+
|
10
|
+
* Don't blow up trying to get current database name on SQLite3
|
11
|
+
|
1
12
|
2.0.3 / 2012-05-07
|
2
13
|
|
3
14
|
* Enhancements
|
data/Gemfile
CHANGED
data/data_miner.gemspec
CHANGED
data/lib/data_miner.rb
CHANGED
@@ -58,7 +58,7 @@ class DataMiner
|
|
58
58
|
# @param [optional, Array<String>] model_names Names of models to be run.
|
59
59
|
#
|
60
60
|
# @return [Array<DataMiner::Run>]
|
61
|
-
def
|
61
|
+
def start(model_names = DataMiner.model_names)
|
62
62
|
Script.uniq do
|
63
63
|
model_names.map do |model_name|
|
64
64
|
model_name.constantize.run_data_miner!
|
@@ -67,7 +67,7 @@ class DataMiner
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# legacy
|
70
|
-
alias :run :
|
70
|
+
alias :run :start
|
71
71
|
|
72
72
|
# Where DataMiner logs to. Defaults to +Rails.logger+ or +ActiveRecord::Base.logger+ if either is available.
|
73
73
|
#
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require 'lock_method'
|
3
2
|
|
4
3
|
class DataMiner
|
5
4
|
# Class methods that are mixed into models (i.e. ActiveRecord::Base)
|
@@ -24,7 +23,7 @@ class DataMiner
|
|
24
23
|
#
|
25
24
|
# @return [DataMiner::Run]
|
26
25
|
def run_data_miner!
|
27
|
-
data_miner_script.
|
26
|
+
data_miner_script.start
|
28
27
|
end
|
29
28
|
|
30
29
|
# Run the data miner scripts of parent associations. Useful for dependencies. Safe to call using +process+.
|
data/lib/data_miner/run.rb
CHANGED
@@ -7,27 +7,29 @@ class DataMiner
|
|
7
7
|
# To create the table, use +DataMiner::Run.auto_upgrade!+, possibly in +db/seeds.rb+ or a database migration.
|
8
8
|
class Run < ::ActiveRecord::Base
|
9
9
|
class << self
|
10
|
-
# If a previous run died, you may find yourself getting +LockMethod::Locked+ exceptions.
|
10
|
+
# If a previous run died and you have manually enabled locking, you may find yourself getting +LockMethod::Locked+ exceptions.
|
11
|
+
#
|
12
|
+
# @note Starting in 2.1.0, runs are no longer locked by default. This method remains in case you want to re-apply locking.
|
11
13
|
#
|
12
14
|
# @param [String] model_names What locks to clear.
|
13
15
|
#
|
14
16
|
# @return [nil]
|
17
|
+
#
|
18
|
+
# @example Re-enable locking (since it was turned off by default in 2.1.0)
|
19
|
+
# require 'data_miner'
|
20
|
+
# require 'lock_method'
|
21
|
+
# DataMiner::Run.lock_method :start
|
15
22
|
def clear_locks(model_names = DataMiner.model_names)
|
23
|
+
return unless defined?(::LockMethod)
|
16
24
|
model_names.each do |model_name|
|
17
25
|
dummy = new
|
18
26
|
dummy.model_name = model_name
|
19
|
-
dummy.lock_method_clear :
|
27
|
+
dummy.lock_method_clear :start
|
20
28
|
end
|
21
29
|
nil
|
22
30
|
end
|
23
|
-
|
24
|
-
# @private
|
25
|
-
def perform(model_name, &blk)
|
26
|
-
run = new
|
27
|
-
run.model_name = model_name
|
28
|
-
run.perform(&blk)
|
29
|
-
end
|
30
31
|
end
|
32
|
+
|
31
33
|
# Raise this exception to skip the current run without causing it to fail.
|
32
34
|
#
|
33
35
|
# @example Avoid running certain data miner scripts too often (because they take too long).
|
@@ -69,7 +71,7 @@ class DataMiner
|
|
69
71
|
validates_presence_of :model_name
|
70
72
|
|
71
73
|
# @private
|
72
|
-
def
|
74
|
+
def start
|
73
75
|
save!
|
74
76
|
begin
|
75
77
|
catch :data_miner_succeed do
|
@@ -89,11 +91,11 @@ class DataMiner
|
|
89
91
|
end
|
90
92
|
self
|
91
93
|
end
|
92
|
-
lock_method :perform
|
93
94
|
|
94
95
|
# @private
|
95
96
|
def as_lock
|
96
|
-
|
97
|
+
database_name = Run.connection.instance_variable_get(:@config).try(:[], :database)
|
98
|
+
[database_name, model_name]
|
97
99
|
end
|
98
100
|
end
|
99
101
|
end
|
data/lib/data_miner/script.rb
CHANGED
@@ -199,7 +199,7 @@ class DataMiner
|
|
199
199
|
# @note A primitive "call stack" is kept that will prevent infinite loops. So, if Country's data miner script calls Province's AND vice-versa, each one will only be run once.
|
200
200
|
#
|
201
201
|
# @return [DataMiner::Run]
|
202
|
-
def
|
202
|
+
def start
|
203
203
|
model_name = model.name
|
204
204
|
# $stderr.write "0 - #{model_name}\n"
|
205
205
|
# $stderr.write "A - current_uniq - #{Script.current_uniq ? 'true' : 'false'}\n"
|
@@ -213,9 +213,11 @@ class DataMiner
|
|
213
213
|
Script.current_stack.clear
|
214
214
|
end
|
215
215
|
Script.current_stack << model_name
|
216
|
-
Run.
|
216
|
+
run = Run.new
|
217
|
+
run.model_name = model_name
|
218
|
+
run.start do
|
217
219
|
steps.each do |step|
|
218
|
-
step.
|
220
|
+
step.start
|
219
221
|
model.reset_column_information
|
220
222
|
end
|
221
223
|
end
|
data/lib/data_miner/step/tap.rb
CHANGED
data/lib/data_miner/version.rb
CHANGED
data/test/test_safety.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_miner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-05-
|
14
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: remote_table
|
@@ -125,22 +125,6 @@ dependencies:
|
|
125
125
|
- - ! '>='
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
|
-
- !ruby/object:Gem::Dependency
|
129
|
-
name: lock_method
|
130
|
-
requirement: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
|
-
requirements:
|
133
|
-
- - ! '>='
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version: 0.5.1
|
136
|
-
type: :runtime
|
137
|
-
prerelease: false
|
138
|
-
version_requirements: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
|
-
requirements:
|
141
|
-
- - ! '>='
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
version: 0.5.1
|
144
128
|
description: Download, pull out of a ZIP/TAR/GZ/BZ2 archive, parse, correct, and import
|
145
129
|
XLS, ODS, XML, CSV, HTML, etc. into your ActiveRecord models. You can also convert
|
146
130
|
units.
|