mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Add email verification job
This commit is contained in:
parent
9ae85f3d74
commit
95a017629e
2 changed files with 45 additions and 1 deletions
43
app/jobs/verify_emails_job.rb
Normal file
43
app/jobs/verify_emails_job.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
class SendEInvoiceJob < Que::Job
|
||||
|
||||
def run(verification_id)
|
||||
email_address_verification = run_condition(EmailAddressVerification
|
||||
.find(run_condition(verification_id)))
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
email_address_verification.verify
|
||||
log_success(email_address_verification)
|
||||
destroy
|
||||
end
|
||||
rescue StandardError => e
|
||||
log_error(verification: email_address_verification, error: e)
|
||||
raise e
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_condition(email_address_verification)
|
||||
destroy if email_address_verification.recently_verified?
|
||||
email_address_verification
|
||||
end
|
||||
|
||||
def logger
|
||||
Rails.logger
|
||||
end
|
||||
|
||||
def log_success(verification)
|
||||
email = verification.try(:email) || verification
|
||||
message = "Email address #{email} verified successfully"
|
||||
logger.info message
|
||||
end
|
||||
|
||||
def log_error(verification:, error:)
|
||||
email = verification.try(:email) || verification
|
||||
message = <<~TEXT.squish
|
||||
There was an error verifying email #{email}.
|
||||
The error message was the following: #{error}
|
||||
This job will retry.
|
||||
TEXT
|
||||
logger.error message
|
||||
end
|
||||
end
|
|
@ -3,7 +3,8 @@ class EmailAddressVerification < ApplicationRecord
|
|||
RECENTLY_VERIFIED_PERIOD = 1.month
|
||||
|
||||
def recently_verified?
|
||||
verified_at > Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
||||
verified_at.present? &&
|
||||
verified_at > Time.zone.now - RECENTLY_VERIFIED_PERIOD
|
||||
end
|
||||
|
||||
def verify
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue