Browse Source

refactor bulk upload with extract method

pull/1267/head
Phil Lee 3 years ago
parent
commit
9b41704c5c
  1. 8
      app/services/bulk_upload/processor.rb

8
app/services/bulk_upload/processor.rb

@ -11,8 +11,10 @@ class BulkUpload::Processor
return send_failure_mail if validator.invalid? return send_failure_mail if validator.invalid?
validator.call validator.call
create_logs if validator.create_logs? create_logs if validator.create_logs?
send_success_mail
send_success_mail if created_logs_and_all_completed?
rescue StandardError => e rescue StandardError => e
Sentry.capture_exception(e) Sentry.capture_exception(e)
send_failure_mail send_failure_mail
@ -23,9 +25,11 @@ class BulkUpload::Processor
private private
def send_success_mail def send_success_mail
if validator.create_logs? && bulk_upload.logs.group(:status).count.keys == %w[completed]
BulkUploadMailer.send_bulk_upload_complete_mail(user:, bulk_upload:).deliver_later BulkUploadMailer.send_bulk_upload_complete_mail(user:, bulk_upload:).deliver_later
end end
def created_logs_and_all_completed?
validator.create_logs? && bulk_upload.logs.group(:status).count.keys == %w[completed]
end end
def send_failure_mail def send_failure_mail

Loading…
Cancel
Save