diff --git a/lib/application_logger.rb b/lib/application_logger.rb new file mode 100644 index 000000000..a9f953f48 --- /dev/null +++ b/lib/application_logger.rb @@ -0,0 +1,11 @@ +class ApplicationLogger + def info(message) + logger.info(message) + end + + def logger + @logger ||= Logger.new(STDOUT).tap do |logger| + logger.formatter = proc { |severity, _datetime, _progname, msg| "#{severity} #{msg}\n" } + end + end +end diff --git a/lib/tasks/budgets.rake b/lib/tasks/budgets.rake index 4e2961198..d9fc8f50f 100644 --- a/lib/tasks/budgets.rake +++ b/lib/tasks/budgets.rake @@ -1,8 +1,11 @@ namespace :budgets do desc "Regenerate ballot_lines_count cache" task calculate_ballot_lines: :environment do - Budget::Ballot.find_each do |ballot| + ApplicationLogger.new.info "Calculating ballot lines" + + Budget::Ballot.find_each.with_index do |ballot, index| Budget::Ballot.reset_counters ballot.id, :lines + print "." if (index % 10_000).zero? end end diff --git a/lib/tasks/polls.rake b/lib/tasks/polls.rake index 0e689e00c..2bd16c46f 100644 --- a/lib/tasks/polls.rake +++ b/lib/tasks/polls.rake @@ -1,6 +1,8 @@ namespace :poll do desc "Generate slugs polls" task generate_slugs: :environment do + ApplicationLogger.new.info "Generating poll slugs" + Poll.find_each do |poll| poll.update_columns(slug: poll.generate_slug, updated_at: Time.current) if poll.generate_slug? end diff --git a/lib/tasks/settings.rake b/lib/tasks/settings.rake index c206af98d..5c4a4db19 100644 --- a/lib/tasks/settings.rake +++ b/lib/tasks/settings.rake @@ -2,6 +2,8 @@ namespace :settings do desc "Remove deprecated settings" task remove_deprecated_settings: :environment do + ApplicationLogger.new.info "Removing deprecated settings" + deprecated_keys = [ "place_name", "banner-style.banner-style-one", diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index a454d88cd..2d68613c5 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -1,6 +1,8 @@ namespace :stats do desc "Generates stats which are not cached yet" task generate: :environment do + ApplicationLogger.new.info "Updating budget and poll stats" + Budget.find_each do |budget| Budget::Stats.new(budget).generate print "." diff --git a/lib/tasks/stats_and_results.rake b/lib/tasks/stats_and_results.rake index 5aa8f7e39..bc4cdacca 100644 --- a/lib/tasks/stats_and_results.rake +++ b/lib/tasks/stats_and_results.rake @@ -1,6 +1,7 @@ namespace :stats_and_results do desc "Migrates stats_enabled and results_enabled data to enabled reports" task migrate_to_reports: :environment do + ApplicationLogger.new.info "Migrating stats and results" Migrations::Reports.new.migrate end end