Skip to content

Commit

Permalink
add loggers to the batch request process
Browse files Browse the repository at this point in the history
  • Loading branch information
vkghub committed Jul 11, 2024
1 parent 6aa3ea9 commit bc18964
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/operations/fdsh/pvc/dmf/request/batch_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BatchProcess
# @option params [Integer] :batch_size the size of each batch (default: {PROCESSING_BATCH_SIZE})
# @return [Dry::Monads::Result] the result of the batch process
def call(params)
create_logger
values = yield validate(params)
job = yield find_job(values[:job_id])
transmissions = yield fetch_transmissions(job)
Expand Down Expand Up @@ -139,7 +140,7 @@ def process_for_transaction_xml(transaction)
append_xml(xml_payload)
@applicants_count += 1
else
p "xml generation failed for #{transaction.id} due to #{result.failure}"
@logger.info("xml generation failed for #{transaction.id} due to #{result.failure}")
end
end

Expand All @@ -163,18 +164,20 @@ def process_batched_requests(batched_requests)
# @param outbound_folder [String] the outbound folder
# @return [Dry::Monads::Result] the result of the create operation
def create_batch_requests(transmissions, values, outbound_folder)
@logger.info("Processing batch requests for #{transmissions.count} transmissions.")
batch_offset = 0
query_offset = 0
transactions_per_file = values[:transactions_per_file]
open_transaction_file

while transmissions.count > query_offset
@logger.info("Processing #{query_offset} transmissions of #{transmissions.count} transmissions.")
batched_requests = batch_request_for(query_offset, transmissions)
process_batched_requests(batched_requests)

query_offset += @batch_size
batch_offset += @batch_size
puts "Processed #{query_offset} transmissions."
@logger.info("Processed #{query_offset} transmissions of #{transmissions.count} transmissions.")

next unless (batch_offset >= transactions_per_file) || (batched_requests.count < @batch_size) || (transmissions.count <= query_offset)

Expand All @@ -184,10 +187,16 @@ def create_batch_requests(transmissions, values, outbound_folder)
open_transaction_file
end

@logger.info("Processed all #{transmissions.count} transmissions.")
Success(outbound_folder)
rescue StandardError => e
@logger.error("Failed during batch processing: #{e.message}")
Failure("Failed during batch processing: #{e.message}")
end

def create_logger
@logger = Logger.new("#{Rails.root}/log/fdsh_pvc_dmf_request_batch_process_#{DateTime.now.strftime('%Y%m%dT%H%M%S%LZ')}.log")
end
end
end
end
Expand Down

0 comments on commit bc18964

Please sign in to comment.