rseed 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWFhM2Q5ZTEyYjhlZjhmM2Y5NzE2MzljODM5ZWQ4YzA3MWZlZTEzMg==
4
+ MGU2YjBiM2ExYWZhZjhiMGVmMjNkNjdkODFjZjMwODliZjA3NWUwYw==
5
5
  data.tar.gz: !binary |-
6
- YTQzMGVjZjljMWUyZDI3NDZmYjBhM2RiNmI3ODZiMTg4NjgwZjljOQ==
6
+ YzRiNjZiOGNkMWI3YTg2NTM1NDFkYmU4M2Y3MmVkOWMwZjliMGQyMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2ZhZGNhMzY5MzQxM2NmNWUyMmFjYzAxY2FlMGNkMjJlYzliNDNhYzA5YjI5
10
- NDk1NTc0YzdjMmE2MmVkYzU2ZTNjN2FmZjBkOTFmMmMyOTQxOTc2ZDZmYjgy
11
- NGFiMmQzNDJiOTBlNGI5NmYyYWE1ZDJiYjdhMDQ4ZjUwNjQxZTk=
9
+ NmVhNjQ2MDNhYWY3ODliNDgyMzRiMDc3YmFiZWI4YWQxZDQ3MTcwMjg5MmIw
10
+ Y2Q4MWU2MTI2ZGE1MmE3YWU3NzBmMzY2MjM1N2Q0MTIwOTNkYjQ4ODI1MTAx
11
+ N2EzNTAwYmFmMTNmMWRmYzFkNGUzZDhhMDRlZDdhZWFmYWVmZjc=
12
12
  data.tar.gz: !binary |-
13
- MjQ4ZWZjNjRjODQ5ZWY0OGEzMzJkMWIzYjc5YTkyZDk1NjE5NTcyOGI2ZDYz
14
- N2RkODc4ZDllZmVlN2Q5ZDc4OTRiMjUzNmQyZTE0ZmRkODEwYmExY2RjMDM1
15
- MmZiNDVlMmFjMjBmZmRkNjQ4NTIyOTcxNmQ1ODJiZjY1YTlkNDg=
13
+ ZjcyNjYxZDJmNjE5ZDQyNWZjZGRiMTM2ZmVkNzRmM2U4MDE3ZTA3MTM3NGI3
14
+ MjdhNTIzNDA2YzI2NWEzZjNkOTUyMDMzMzZkNWQxNDc4MjRkMzE1ZjYxMTlk
15
+ NjRiNWY5OTBjNjFkY2JhNDFlNDc5ZWU4MGNkMWM0ZDBmMWIyYzE=
data/README.rdoc CHANGED
@@ -124,6 +124,13 @@ These rake tasks allow you to run seeds manually:
124
124
 
125
125
  In this case the file in db/rseed/users.csv would be run through the converter UserConverter. The options specified are available within the converter. In this case options["give_admin_access"] will evaluate to "true".
126
126
 
127
+ == Processor Options
128
+
129
+ * :within_transaction
130
+
131
+ Setting this to true will wrap the entire deserialize in an transaction, avoiding calling a commit after each line.
132
+ For large data sets, this should speed up insertion.
133
+
127
134
  == Seeding
128
135
 
129
136
  If you want to seed your Rails application using Rseed. The best method is to add lines like the following to db/seeds.rb
data/lib/rseed/helpers.rb CHANGED
@@ -39,8 +39,9 @@ module Rseed
39
39
  progress_bar.format "#{"Complete".green} %t <%B> %C (%a)"
40
40
  progress_bar.finish if progress_bar.total
41
41
  when :error
42
- processor.logger.error "Error processing record #{meta[:record_count]}"
42
+ processor.logger.error "Error during processing"
43
43
  processor.logger.error result[:message].to_s.red
44
+ processor.logger.error meta.to_s.cyan if meta
44
45
  processor.logger.error result[:error]
45
46
  processor.logger.error result[:backtrace].join('\n') if result[:backtrace]
46
47
  end
@@ -22,6 +22,7 @@ module Rseed
22
22
  end
23
23
  converter.options = HashWithIndifferentAccess.new(converter_options)
24
24
  end
25
+ @within_transaction = options[:within_transaction]
25
26
  @adapter = adapter
26
27
  @converter = converter
27
28
  end
@@ -46,42 +47,45 @@ module Rseed
46
47
  if @converter.before_deserialize
47
48
  yield :processing
48
49
  start_time = Time.now
49
- adapter.process do |values, meta|
50
- result = {values: values}
51
- meta ||= {}
52
- begin
53
- if @converter.deserialize_raw(values)
54
- result[:success] = true
55
- else
50
+ wrap_inserts do
51
+ adapter.process do |values, meta|
52
+ result = {values: values}
53
+ meta ||= {}
54
+ begin
55
+ if @converter.deserialize_raw(values)
56
+ result[:success] = true
57
+ else
58
+ result[:success] = false
59
+ result[:message] = "Failed to convert"
60
+ result[:error] = @converter.error
61
+ end
62
+ rescue Exception => e
56
63
  result[:success] = false
57
- result[:message] = "Failed to convert"
58
- result[:error] = @converter.error
64
+ result[:message] = "Exception during deserialize"
65
+ result[:error] = e.message
66
+ result[:backtrace] = e.backtrace
59
67
  end
60
- rescue Exception => e
61
- result[:success] = false
62
- result[:message] = "Exception during deserialize"
63
- result[:error] = e.message
64
- result[:backtrace] = e.backtrace
65
- end
66
68
 
67
- total_records = meta[:total_records] unless meta[:total_records].nil?
68
- record_count = meta[:record_count] unless meta[:record_count].nil?
69
- # Calculate the ETA
70
- if record_count and total_records
71
- remaining = total_records - record_count
72
- tpr = (Time.now - start_time)/record_count
73
- meta[:eta] = remaining * tpr
74
- end
69
+ total_records = meta[:total_records] unless meta[:total_records].nil?
70
+ record_count = meta[:record_count] unless meta[:record_count].nil?
71
+ # Calculate the ETA
72
+ if record_count and total_records
73
+ remaining = total_records - record_count
74
+ tpr = (Time.now - start_time)/record_count
75
+ meta[:eta] = remaining * tpr
76
+ end
75
77
 
76
- # Log any errors
77
- unless result[:success]
78
- logger.error result[:message].to_s.red
79
- logger.error result[:error].to_s.red
80
- logger.error result[:backtrace].to_s unless result[:backtrace].to_s.blank?
78
+ # Log any errors
79
+ unless result[:success]
80
+ logger.error result[:message].to_s.red
81
+ logger.error result[:error].to_s.red
82
+ logger.error meta.to_s.cyan
83
+ logger.error result[:backtrace].to_s unless result[:backtrace].to_s.blank?
84
+ end
85
+ yield :processing, result, meta
81
86
  end
82
- yield :processing, result, meta
87
+ @converter.after_deserialize
83
88
  end
84
- @converter.after_deserialize
85
89
  else
86
90
  yield :error, {success: false, message: 'Before deserialize failed', error: @converter.error}
87
91
  end
@@ -91,7 +95,19 @@ module Rseed
91
95
  rescue Exception => e
92
96
  yield :error, {success: false, message: 'Exception during Processing', error: e.message, backtrace: e.backtrace}
93
97
  end
94
- yield :complete, {success: true }, {total_records: total_records, record_count: record_count}
98
+ yield :complete, {success: true}, {total_records: total_records, record_count: record_count}
99
+ end
100
+
101
+ protected
102
+
103
+ def wrap_inserts &block
104
+ if @within_transaction
105
+ ActiveRecord::Base.transaction do
106
+ yield
107
+ end
108
+ else
109
+ yield
110
+ end
95
111
  end
96
112
  end
97
113
  end
data/lib/rseed/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rseed
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rseed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Monagle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize