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 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
@@ -10,6 +10,7 @@ gem 'mysql2'
10
10
  gem 'rake'
11
11
  gem 'yard'
12
12
  gem 'earth'
13
+ gem 'lock_method'
13
14
  if RUBY_VERSION >= '1.9'
14
15
  gem 'unicode_utils'
15
16
  end
@@ -24,5 +24,4 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'errata', '>=1.0.1'
25
25
  s.add_runtime_dependency 'active_record_inline_schema'
26
26
  s.add_runtime_dependency 'aasm'
27
- s.add_runtime_dependency 'lock_method', '>=0.5.1'
28
27
  end
@@ -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 perform(model_names = DataMiner.model_names)
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 :perform
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.perform
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+.
@@ -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 :perform
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 perform
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
- [Run.connection.current_database, model_name]
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
@@ -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 perform
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.perform(model_name) do
216
+ run = Run.new
217
+ run.model_name = model_name
218
+ run.start do
217
219
  steps.each do |step|
218
- step.perform
220
+ step.start
219
221
  model.reset_column_information
220
222
  end
221
223
  end
@@ -83,7 +83,7 @@ class DataMiner
83
83
  end
84
84
 
85
85
  # @private
86
- def perform
86
+ def start
87
87
  table.each do |row|
88
88
  record = model.send "find_or_initialize_by_#{@key}", attributes[@key].read(row)
89
89
  attributes.each { |_, attr| attr.set_from_row record, row }
@@ -37,7 +37,7 @@ class DataMiner
37
37
  end
38
38
 
39
39
  # @private
40
- def perform
40
+ def start
41
41
  DataMiner::Script.uniq do
42
42
  if blk
43
43
  model.instance_eval(&blk)
@@ -57,7 +57,7 @@ class DataMiner
57
57
  end
58
58
 
59
59
  # @private
60
- def perform
60
+ def start
61
61
  [ source_table_name, model.table_name ].each do |possible_obstacle|
62
62
  if connection.table_exists? possible_obstacle
63
63
  connection.drop_table possible_obstacle
@@ -1,3 +1,3 @@
1
1
  class DataMiner
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -2,6 +2,9 @@
2
2
  require 'helper'
3
3
  require 'earth'
4
4
 
5
+ require 'lock_method'
6
+ DataMiner::Run.lock_method :start
7
+
5
8
  # use earth, which has a plethora of real-world data_miner blocks
6
9
  Earth.init :locality, :pet, :load_data_miner => true, :apply_schemas => true
7
10
 
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.3
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-07 00:00:00.000000000 Z
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.