Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

22 lines
925 B

class CreateAddressesCsvJob < ApplicationJob
queue_as :default
BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8
def perform(organisation, log_type)
csv_service = Csv::MissingAddressesCsvService.new(organisation, [])
case log_type
when "lettings"
csv_string = csv_service.create_lettings_addresses_csv
filename = "#{['lettings-logs-addresses', organisation.name, Time.zone.now].compact.join('-')}.csv"
when "sales"
csv_string = csv_service.create_sales_addresses_csv
filename = "#{['sales-logs-addresses', organisation.name, Time.zone.now].compact.join('-')}.csv"
end
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string)
Rails.logger.info("Created addresses file: #{filename}")
end
end