Browse Source

CLDC-2684 Allow full export per year (#1875)

* Allow full export for specific year

* Update production manifest

* Call export_xml_lettings_logs with nil if no year is given

* Rename method
pull/1880/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
3bd6cab5c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/services/exports/lettings_log_export_service.rb
  2. 5
      lib/tasks/data_export.rake
  3. 2
      manifest.yml
  4. 21
      spec/lib/tasks/data_export_spec.rb
  5. 10
      spec/services/exports/lettings_log_export_service_spec.rb

8
app/services/exports/lettings_log_export_service.rb

@ -8,13 +8,13 @@ module Exports
@logger = logger @logger = logger
end end
def export_xml_lettings_logs(full_update: false) def export_xml_lettings_logs(full_update: false, collection_year: nil)
start_time = Time.zone.now start_time = Time.zone.now
daily_run_number = get_daily_run_number daily_run_number = get_daily_run_number
archives_for_manifest = {} archives_for_manifest = {}
base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1 base_number = LogsExport.where(empty_export: false).maximum(:base_number) || 1
recent_export = LogsExport.order("started_at").last recent_export = LogsExport.order("started_at").last
available_collection_years.each do |collection| collection_years_to_export(collection_year).each do |collection|
export = build_export_run(collection, start_time, base_number, full_update) export = build_export_run(collection, start_time, base_number, full_update)
archives = write_export_archive(export, collection, start_time, recent_export, full_update) archives = write_export_archive(export, collection, start_time, recent_export, full_update)
@ -267,7 +267,9 @@ module Exports
xml_doc_to_temp_file(doc) xml_doc_to_temp_file(doc)
end end
def available_collection_years def collection_years_to_export(collection_year)
return [collection_year] if collection_year.present?
FormHandler.instance.lettings_forms.values.map { |f| f.start_date.year }.uniq FormHandler.instance.lettings_forms.values.map { |f| f.start_date.year }.uniq
end end
end end

5
lib/tasks/data_export.rake

@ -12,10 +12,11 @@ namespace :core do
end end
desc "Export all data XMLs for import into Central Data System (CDS)" desc "Export all data XMLs for import into Central Data System (CDS)"
task full_data_export_xml: :environment do |_task, _args| task :full_data_export_xml, %i[year] => :environment do |_task, args|
collection_year = args[:year].presence
storage_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"]) storage_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"])
export_service = Exports::LettingsLogExportService.new(storage_service) export_service = Exports::LettingsLogExportService.new(storage_service)
export_service.export_xml_lettings_logs(full_update: true) export_service.export_xml_lettings_logs(full_update: true, collection_year:)
end end
end end

2
manifest.yml

@ -34,8 +34,10 @@ applications:
memory: 1G memory: 1G
- type: worker - type: worker
command: bundle exec sidekiq -t 3 command: bundle exec sidekiq -t 3
disk_quota: 4G
health-check-type: process health-check-type: process
instances: 2 instances: 2
memory: 8G
env: env:
RAILS_ENV: production RAILS_ENV: production
host: submit-social-housing-lettings-sales-data host: submit-social-housing-lettings-sales-data

21
spec/lib/tasks/data_export_spec.rb

@ -28,21 +28,22 @@ describe "rake core:data_export", type: task do
end end
context "when running full export" do context "when running full export" do
let(:storage_service) { instance_double(Storage::S3Service) }
let(:paas_config_service) { instance_double(Configuration::PaasConfigurationService) }
let(:export_service) { instance_double(Exports::LettingsLogExportService) }
let(:task) { Rake::Task["core:full_data_export_xml"] } let(:task) { Rake::Task["core:full_data_export_xml"] }
before do context "with all available years" do
allow(Storage::S3Service).to receive(:new).and_return(storage_service) it "calls the export service" do
allow(Configuration::PaasConfigurationService).to receive(:new).and_return(paas_config_service) expect(export_service).to receive(:export_xml_lettings_logs).with(full_update: true, collection_year: nil)
allow(Exports::LettingsLogExportService).to receive(:new).and_return(export_service)
task.invoke
end
end end
it "calls the export service" do context "with a specific year" do
expect(export_service).to receive(:export_xml_lettings_logs).with(full_update: true) it "calls the export service" do
expect(export_service).to receive(:export_xml_lettings_logs).with(full_update: true, collection_year: 2022)
task.invoke task.invoke(2022)
end
end end
end end
end end

10
spec/services/exports/lettings_log_export_service_spec.rb

@ -219,6 +219,16 @@ RSpec.describe Exports::LettingsLogExportService do
export_service.export_xml_lettings_logs export_service.export_xml_lettings_logs
end end
it "generates zip export files only for specified year" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename2, any_args)
expect(Rails.logger).to receive(:info).with("Building export run for 2022")
expect(Rails.logger).to receive(:info).with("Creating core_2022_2023_apr_mar_f0001_inc0001 - 1 logs")
expect(Rails.logger).to receive(:info).with("Added core_2022_2023_apr_mar_f0001_inc0001_pt001.xml")
expect(Rails.logger).to receive(:info).with("Writing core_2022_2023_apr_mar_f0001_inc0001.zip")
export_service.export_xml_lettings_logs(collection_year: 2022)
end
end end
end end

Loading…
Cancel
Save