Handle QrMatching response - mock

This commit is contained in:
bilal
2020-06-02 22:23:19 +02:00
parent 3690268f83
commit e3d4d22a34
2 changed files with 26 additions and 23 deletions

View File

@@ -8,22 +8,25 @@ class MatchAppearanceReleasesJob < ApplicationJob
payload = { request_id: matching_request.id, bucket: aws_bucket_name, files: attachments}
response = BrayniacAI::AppearanceReleaseMatching.match_attachments payload
# BrayniacAI::QrMatching.enable_logging
# response = BrayniacAI::QrMatching.create! payload
matches = response[:matches] || []
errors = response[:errors] || []
handle_matches matches, project
handle_errors errors
matching_request.destroy
end
private
def handle_matches(matches, project)
matches.each do |match|
contract = match[:contract]
headshot = match[:headshot]
contract = match[:contracts].blank? ? nil : match[:contracts].first
headshot = match[:headshots].blank? ? nil : match[:headshots].first
identifier = match[:identifier]
next if contract.nil? && headshot.nil?
identified_release = identifier.blank? ? nil : AppearanceRelease.find_by(identifier: identifier)
if identified_release.nil?
create_release project, contract, headshot, identifier
@@ -33,13 +36,6 @@ class MatchAppearanceReleasesJob < ApplicationJob
end
end
def handle_errors(errors)
logger.error "== MATCHING ERRORS ==" unless errors.empty?
errors.each do |error|
logger.error "[#{error[:error_code]}] #{error[:file]}"
end
end
def create_release(project, contract, headshot, identifier)
random_contract_no = AppearanceRelease.random_contract_number.to_s
is_incomplete = contract.nil? || headshot.nil?