Sha256: ef18d209a6f60d49fb6266e1ca2461af91a94afecec408ef9fdc414974c312ab

Contents?: true

Size: 1.41 KB

Versions: 29

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/feeds"

module Renalware
  module Feeds
    module Files
      module PracticeMemberships
        class ImportJob < ApplicationJob
          include StringLogging
          include Feeds::Job
          FILE_TO_EXTRACT_FROM_ARCHIVE = /epracmem.csv/.freeze

          def perform(file)
            logging_to_stringio(strio = StringIO.new)
            log "Before upload there are #{practice_membership_count} practice memberships"
            file.update!(status: :processing, attempts: file.attempts + 1)
            status = :success
            elapsed_ms = Benchmark.ms { process_archive(file.location) }
            log "After upload there are #{practice_membership_count} practice memberships"
          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)
              PracticeMemberships::ImportCSV.new(csv_path).call
            end
          end

          def practice_membership_count
            Patients::PracticeMembership.count
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
renalware-core-2.0.113 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.112 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.111 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.110 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.109 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.108 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.106 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.105 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.104 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.103 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.102 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.101 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.100 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.99 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.98 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.97 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.96 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.95 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.94 app/models/renalware/feeds/files/practice_memberships/import_job.rb
renalware-core-2.0.93 app/models/renalware/feeds/files/practice_memberships/import_job.rb