Sha256: 1d3fb7f0a767595e4613f708d8c6536ea6a79f4c9d753aaf52b57af577e2ebff

Contents?: true

Size: 1.43 KB

Versions: 31

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/feeds"

module Renalware
  module Feeds
    module Files
      module PrimaryCarePhysicians
        class ImportJob < ApplicationJob
          include StringLogging
          include Feeds::Job

          FILE_TO_EXTRACT_FROM_ARCHIVE = /^egpcur.csv$/.freeze
          def perform(file)
            logging_to_stringio(strio = StringIO.new)
            log "PrimaryCarePhysician count before update: #{primary_care_physician_count}"
            file.update!(status: :processing, attempts: file.attempts + 1)
            status = :success
            elapsed_ms = Benchmark.ms { process_archive(file.location) }
            log "PrimaryCarePhysician count after update: #{primary_care_physician_count}"
          rescue StandardError => e
            Rails.logger.error(formatted_exception(e))
            status = :failure
            raise e
          ensure
            file.update!(status: status, result: strio.string, time_taken: elapsed_ms)
          end

          private

          def process_archive(location)
            ZipArchive.new(location).unzip do |files|
              csv_path = find_file_in(files, FILE_TO_EXTRACT_FROM_ARCHIVE)
              PrimaryCarePhysicians::ImportCSV.new(csv_path).call
            end
          end

          def primary_care_physician_count
            Renalware::Patients::PrimaryCarePhysician.count
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.1.0 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.167 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.166 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.165 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.164 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.163 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.162 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.161 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.160 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.159 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.158 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.157 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.156 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.155 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.153 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.152 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.151 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.149 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.148 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb