Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task to upgrade to a new release #3590

Merged
merged 5 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def deploysecret(key)
after :published, "refresh_sitemap"

after :finishing, "deploy:cleanup"


desc "Deploys and runs the tasks needed to upgrade to a new release"
task :upgrade do
after "add_new_settings", "execute_release_tasks"
invoke "deploy"
end
end

task :install_bundler_gem do
Expand All @@ -70,11 +77,21 @@ def deploysecret(key)
end

task :add_new_settings do
on roles(:app) do
on roles(:db) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "settings:add_new_settings"
end
end
end
end

task :execute_release_tasks do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "consul:execute_release_tasks"
end
end
end
end
11 changes: 11 additions & 0 deletions lib/application_logger.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/tasks/budgets.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
namespace :budgets do
desc "Regenerate ballot_lines_count cache"
task calculate_ballot_lines: :environment do
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

namespace :email do

desc "Sends emails to authors of selected investments"
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/consul.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace :consul do
desc "Runs tasks needed to upgrade to the latest version"
task execute_release_tasks: "execute_release_1.0.0_tasks"

desc "Runs tasks needed to upgrade from 1.0.0-beta to 1.0.0"
task "execute_release_1.0.0_tasks": [
"poll:generate_slugs",
"stats_and_results:migrate_to_reports",
"budgets:calculate_ballot_lines",
"settings:remove_deprecated_settings",
"stats:generate"
]
end
2 changes: 2 additions & 0 deletions lib/tasks/polls.rake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/tasks/regenerate_ballot_lines_cache.rake

This file was deleted.

2 changes: 2 additions & 0 deletions lib/tasks/settings.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/stats.rake
Original file line number Diff line number Diff line change
@@ -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 "."
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/stats_and_results.rake
Original file line number Diff line number Diff line change
@@ -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