Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add start and end messages to seeding with total time and a reference…

… to which contexts were run..
  • Loading branch information...
commit 066a74b30a5fa072859bfc9e8b05c9feac9f01b2 1 parent bda1829
@midas authored
View
15 lib/generators/prepare_genesis/templates/genesis.rake
@@ -8,13 +8,18 @@ namespace :db do
contexts = ENV['CONTEXTS']
unless contexts.nil? || contexts.empty?
+ using_contexts = true
contexts = expand_contexts if contexts == 'all'
contexts.split( ',' ).each do |context|
seeds += Dir[File.join( Rails.root, 'db', 'seeds', 'contexts', context, '*.rb' )]
end
end
+
+
+ puts "", message( contexts, :using_contexts => using_contexts, :start => true ), ""
Genesis::Seeder.run( seeds, ENV['VERSION'] || nil, ignores )
+ puts message( contexts, :using_contexts => using_contexts ), "", ""
end
desc "Drops and recreates all tables along with seeding the database"
@@ -71,3 +76,13 @@ end
def expand_contexts
Dir[File.join( contexts_root, '*' )].map { |d| d.split( '/' ).last }.join ','
end
+
+def message( contexts, options={} )
+ msg = options[:using_contexts] ?
+ "*** #{start_or_end_word( options )} seeding (contexts: #{contexts.split(',').join(', ')})" :
+ "*** #{start_or_end_word( options )} seeding"
+end
+
+def start_or_end_word( options )
+ return options[:start] ? 'Start' : 'End'
+end
View
17 lib/genesis/seeder.rb
@@ -43,7 +43,7 @@ def self.seed_version_table_exists?
#
def self.run( seeds=[], to_version=nil, ignores=[] )
ignores << 'genesis_callbacks.rb'
- @separator_size = 79
+ @separator_size = 95
determine_current_version
map_versions( seeds, ignores )
raise 'There are no seeds to execute.' if @versions_map.empty?
@@ -115,12 +115,16 @@ def self.run_seeds
GenesisCallbacks.send( callback_method ) if GenesisCallbacks.respond_to?( callback_method )
end
+ @time_start_seeding = Time.now
@to_run.each { |version, metadata| self.run_seed( version, metadata ) }
+ @time_end_seeding = Time.now
if should_run_callbacks
callback_method = :"after_#{@method}"
GenesisCallbacks.send( callback_method ) if GenesisCallbacks.respond_to?( callback_method )
end
+
+ log_seeding_finish
end
def self.run_seed( version, metadata )
@@ -143,14 +147,21 @@ def self.run_seed( version, metadata )
def self.log_entry_start( class_name )
entry = "== #{class_name}: seeding (#{@method.to_s}) "
- entry << "="*(@separator_size-entry.length+1) << "\n"
+ entry << "="*(@separator_size-entry.length) << "\n"
puts entry
RAILS_DEFAULT_LOGGER.info entry
end
def self.log_entry_finish( class_name, total_time )
entry = "== #{class_name}: seeded (#{@method.to_s}) (#{total_time}s) "
- entry << "="*(@separator_size-entry.length) << "\n\n"
+ num_to_finish = @separator_size-entry.length
+ entry << "="*(num_to_finish) << "\n\n" if num_to_finish > 0
+ puts entry
+ RAILS_DEFAULT_LOGGER.info entry
+ end
+
+ def self.log_seeding_finish
+ entry = "*** Seeding total time: #{@time_end_seeding - @time_start_seeding}s"
puts entry
RAILS_DEFAULT_LOGGER.info entry
end
View
15 rails_generators/prepare_seeding/templates/genesis.rake
@@ -8,13 +8,18 @@ namespace :db do
contexts = ENV['CONTEXTS']
unless contexts.nil? || contexts.empty?
+ using_contexts = true
contexts = expand_contexts if contexts == 'all'
contexts.split( ',' ).each do |context|
seeds += Dir[File.join( Rails.root, 'db', 'seeds', 'contexts', context, '*.rb' )]
end
end
+
+
+ puts "", message( contexts, :using_contexts => using_contexts, :start => true ), ""
Genesis::Seeder.run( seeds, ENV['VERSION'] || nil, ignores )
+ puts message( contexts, :using_contexts => using_contexts ), "", ""
end
desc "Drops and recreates all tables along with seeding the database"
@@ -71,3 +76,13 @@ end
def expand_contexts
Dir[File.join( contexts_root, '*' )].map { |d| d.split( '/' ).last }.join ','
end
+
+def message( contexts, options={} )
+ msg = options[:using_contexts] ?
+ "*** #{start_or_end_word( options )} seeding (contexts: #{contexts.split(',').join(', ')})" :
+ "*** #{start_or_end_word( options )} seeding"
+end
+
+def start_or_end_word( options )
+ return options[:start] ? 'Start' : 'End'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.