Sha256: 3925f4e05cdd6e7358f7aa35413e1b11dda77cf8dbf5167fef21934d858dce9f
Contents?: true
Size: 1.67 KB
Versions: 62
Compression:
Stored size: 1.67 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/ def perform(file) logging_to_stringio(strio = StringIO.new) log "Before upload there are #{practice_membership_count} active and "\ "#{inactive_practice_membership_count} inactive 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} active and "\ "#{inactive_practice_membership_count} inactive 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 def inactive_practice_membership_count Patients::PracticeMembership.deleted.count end end end end end end
Version data entries
62 entries across 62 versions & 1 rubygems