Class: Renalware::Patients::SyncGpsViaFileDownloadJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Renalware::Patients::SyncGpsViaFileDownloadJob
- Defined in:
- app/models/renalware/patients/sync_gps_via_file_download_job.rb
Constant Summary collapse
- ODS_DOWNLOADABLES =
{ primary_care_physicians: { url: "https://files.digital.nhs.uk/assets/ods/current/egpcur.zip", filename: "egpcur.zip" }, practice_memberships: { url: "https://files.digital.nhs.uk/assets/ods/current/epracmem.zip", filename: "epracmem.zip" } }.freeze
Instance Method Summary collapse
-
#perform ⇒ Object
Now we have brought practices up to date, update GPs and their membership in practices.
Instance Method Details
#perform ⇒ Object
Now we have brought practices up to date, update GPs and their membership in practices. Download the relevant zip file, save it as a Feeds::File (the zip file will be copied to the uploads dir) and kick off a sync job to import the data, which it does by unzipping the file, extracting the csv and using a PG function to upsert the contents. Note we cannot reliably use an aysnc job here as the order of execution of the 3 updates - practices, gps, practice memberships - is strict.
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/renalware/patients/sync_gps_via_file_download_job.rb', line 31 def perform ODS_DOWNLOADABLES.each do |type, | # Download the ODS file to a temporary location - must be /tmp dir on linux # in order for PG to have access - hence using Tempfile tmp_file = Pathname(Tempfile.new([:filename])) `wget -O #{tmp_file} #{[:url]}` file = create_feed_file(type, tmp_file) Renalware::Feeds::Files::ImportJobFactory.job_class_for(file.file_type).perform_now(file) end end |