Browse Source

CLDC-2383 Sidekiq graceful restart (#1674)

* allow sidekiq to shutdown gracefully

* delete existing errors before bulk upload run

* fix typo
pull/1688/head
Phil Lee 2 years ago committed by GitHub
parent
commit
aa4a1677b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/services/bulk_upload/processor.rb
  2. 2
      config/cloud_foundry/review_manifest.yml
  3. 4
      config/initializers/sidekiq.rb
  4. 4
      manifest.yml
  5. 10
      spec/services/bulk_upload/processor_spec.rb

6
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:)

2
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

4
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

4
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:

10
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(

Loading…
Cancel
Save