From aa4a1677b23cb3558614c9ba85fd3631540eda52 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 2 Jun 2023 09:58:38 +0100 Subject: [PATCH] CLDC-2383 Sidekiq graceful restart (#1674) * allow sidekiq to shutdown gracefully * delete existing errors before bulk upload run * fix typo --- app/services/bulk_upload/processor.rb | 6 ++++++ config/cloud_foundry/review_manifest.yml | 2 +- config/initializers/sidekiq.rb | 4 ++++ manifest.yml | 4 ++-- spec/services/bulk_upload/processor_spec.rb | 10 ++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index 16d0a067d..711996fcf 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -6,6 +6,8 @@ class BulkUpload::Processor end def call + destroy_any_existing_errors_from_prior_run + download return send_failure_mail(errors: validator.errors.full_messages) if validator.invalid? @@ -46,6 +48,10 @@ class BulkUpload::Processor private + def destroy_any_existing_errors_from_prior_run + bulk_upload.bulk_upload_errors.destroy_all + end + def send_how_to_fix_upload_mail BulkUploadMailer .send_how_to_fix_upload_mail(bulk_upload:) diff --git a/config/cloud_foundry/review_manifest.yml b/config/cloud_foundry/review_manifest.yml index f715306b0..55913dc37 100644 --- a/config/cloud_foundry/review_manifest.yml +++ b/config/cloud_foundry/review_manifest.yml @@ -8,7 +8,7 @@ defaults: &defaults instances: 1 memory: 1G - type: worker - command: bundle exec sidekiq + command: bundle exec sidekiq -t 3 health-check-type: process instances: 1 health-check-type: http diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 597de6400..c8e38e1d7 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -32,4 +32,8 @@ Sidekiq.configure_server do |config| config.on(:startup) do Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/sidekiq_cron_schedule.yml") end + + config.on(:shutdown) do + Sidekiq::CLI.instance.launcher.quiet + end end diff --git a/manifest.yml b/manifest.yml index c8f26f9b0..f34074d39 100644 --- a/manifest.yml +++ b/manifest.yml @@ -8,7 +8,7 @@ defaults: &defaults instances: 2 memory: 1G - type: worker - command: bundle exec sidekiq + command: bundle exec sidekiq -t 3 health-check-type: process instances: 2 health-check-type: http @@ -31,7 +31,7 @@ applications: instances: 4 memory: 1G - type: worker - command: bundle exec sidekiq + command: bundle exec sidekiq -t 3 health-check-type: process instances: 2 env: diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 6c250bbb6..2314a325f 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -8,6 +8,16 @@ RSpec.describe BulkUpload::Processor do let(:owning_org) { create(:organisation, old_visible_id: 123) } describe "#call" do + context "when errors exist from prior job run" do + let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } + + it "destroys existing errors" do + processor.call + + expect { existing_error.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + context "when the bulk upload itself is not considered valid" do let(:mock_downloader) do instance_double(