Sha256: db9b358818f4eddbb5442ac3e1668364388941222ed1c969a081243b5b7c9139

Contents?: true

Size: 1.52 KB

Versions: 21

Compression:

Stored size: 1.52 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

          # rubocop:disable Metrics/AbcSize
          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
          # rubocop:enable Metrics/AbcSize

          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

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.0.136 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.135 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.134 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.133 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.132 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.131 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.130 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.129 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.128 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.127 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.126 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.125 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.124 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.123 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.121 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.120 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.119 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.118 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.117 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb
renalware-core-2.0.116 app/models/renalware/feeds/files/primary_care_physicians/import_job.rb