From d4048a6e657ffa627b46ddda5a5212027d7e7e82 Mon Sep 17 00:00:00 2001 From: Eric O Date: Thu, 21 Sep 2023 19:08:16 -0400 Subject: [PATCH] Deployment troubleshooting: rake task updates --- config/deploy.rb | 1 + lib/tasks/derivativo/ci.rake | 82 +++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index e9f9374..6d1168c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -70,6 +70,7 @@ with rails_env: fetch(:rails_env) do execute :echo, '"Got here 1"' execute :rake, 'resque:test' + execute :rake, 'resque:restart_workers' execute :echo, '"Got here 2"' end end diff --git a/lib/tasks/derivativo/ci.rake b/lib/tasks/derivativo/ci.rake index 03119c7..c8d819b 100644 --- a/lib/tasks/derivativo/ci.rake +++ b/lib/tasks/derivativo/ci.rake @@ -1,51 +1,55 @@ # frozen_string_literal: true -# Only include this task in development and test environments (because rspec is only available -# in those environments and we don't ever want to run CI tasks in other environments). -if ['development', 'test'].include?(Rails.env) - namespace :derivativo do - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:rspec) do |spec| - spec.rspec_opts ||= [] - spec.rspec_opts << '--backtrace' if ENV['CI'] - end +namespace :derivativo do + require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:rspec) do |spec| + spec.rspec_opts ||= [] + spec.rspec_opts << '--backtrace' if ENV['CI'] + end - require 'rubocop/rake_task' - desc 'Run style checker' - RuboCop::RakeTask.new(:rubocop) do |task| - task.requires << 'rubocop-rspec' - task.fail_on_error = true - end + require 'rubocop/rake_task' + desc 'Run style checker' + RuboCop::RakeTask.new(:rubocop) do |task| + task.requires << 'rubocop-rspec' + task.fail_on_error = true + end - desc 'CI build without rubocop' - task ci_nocop: ['derivativo:setup:config_files', :environment, 'derivativo:ci_specs'] + desc 'CI build without rubocop' + task ci_nocop: ['derivativo:setup:config_files', :environment, 'derivativo:ci_specs'] - desc 'CI build with Rubocop validation' - task ci: ['derivativo:setup:config_files', :environment, 'derivativo:rubocop', 'derivativo:ci_specs'] + desc 'CI build with Rubocop validation' + task ci: ['derivativo:setup:config_files', :environment, 'derivativo:rubocop', 'derivativo:ci_specs'] - desc 'CI build just running specs' - task ci_specs: :environment do - rspec_system_exit_failure_exception = nil + desc 'CI build just running specs' + task ci_specs: :environment do + rspec_system_exit_failure_exception = nil - duration = Benchmark.realtime do - ENV['RAILS_ENV'] = 'test' - Rails.env = ENV['RAILS_ENV'] + duration = Benchmark.realtime do + ENV['RAILS_ENV'] = 'test' + Rails.env = ENV['RAILS_ENV'] - Rake::Task['db:environment:set'].invoke - Rake::Task['db:drop'].invoke - Rake::Task['db:create'].invoke - Rake::Task['db:migrate'].invoke - begin - Rake::Task['derivativo:rspec'].invoke - rescue SystemExit => e - rspec_system_exit_failure_exception = e - end + Rake::Task['db:environment:set'].invoke + Rake::Task['db:drop'].invoke + Rake::Task['db:create'].invoke + Rake::Task['db:migrate'].invoke + begin + Rake::Task['derivativo:rspec'].invoke + rescue SystemExit => e + rspec_system_exit_failure_exception = e end - puts "CI run finished in #{duration} seconds." - # If present, re-raise any caught exit exception after CI duration display, - # so we can still display the run time even when a system exception comes up. - # This exception triggers an exit call with the original error code sent out by rspec failure. - raise rspec_system_exit_failure_exception unless rspec_system_exit_failure_exception.nil? end + puts "CI run finished in #{duration} seconds." + # If present, re-raise any caught exit exception after CI duration display, + # so we can still display the run time even when a system exception comes up. + # This exception triggers an exit call with the original error code sent out by rspec failure. + raise rspec_system_exit_failure_exception unless rspec_system_exit_failure_exception.nil? end +rescue LoadError => e + # Be prepared to rescue so that this rake file can be loaded in environments where RSpec + # is unavailable (i.e. production/deployed environments). + puts '[Warning] Exception creating ci/rubocop/rspec rake tasks. '\ + 'This message can be ignored in environments that intentionally '\ + 'do not pull in certain development/test environment gems '\ + '(i.e. production/deployed environments).' + puts e end