Class: OtpJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- OtpJob
- Includes:
- Auth::JobExceptionHandler, Auth::Mailgun, Auth::TwoFactorOtp
- Defined in:
- app/jobs/otp_job.rb
Overview
require “/home/bhargav/Github/auth/lib/auth/two_factor_otp”
Constant Summary
Constants included from Auth::TwoFactorOtp
Auth::TwoFactorOtp::TWO_FACTOR_BASE_URL, Auth::TwoFactorOtp::TWO_FACTOR_TRANSACTIONAL_SMS_URL
Instance Method Summary collapse
-
#perform(args) ⇒ Object
expected array of arguments is: 0 => resource class as string 1 => resource as json serialized, by calling JSON.generate() 2 => job_type : either “send_sms_otp” or “verify_sms_otp” 3 => hash of additional arguments if any.
-
#StandardError ⇒ Object
we currently log all exceptions to redis.
Methods included from Auth::JobExceptionHandler
Methods included from Auth::Mailgun
#add_webhook_identifier_to_email, #email_webhook, set_webhook_identifier
Methods included from Auth::TwoFactorOtp
#auth_gen, check_errors, #clear_redis_user_otp_hash, #log_error_to_redis, #resource, #send_otp_response, #send_transactional_sms, set_webhook_identifier, #sms_webhook, #transactional_sms_delivered?, #transactional_sms_failed?, #transactional_sms_pending?, #typhoeus_timeout, #verify, #verify_otp_response
Instance Method Details
#perform(args) ⇒ Object
expected array of arguments is: 0 => resource class as string 1 => resource as json serialized, by calling JSON.generate() 2 => job_type : either “send_sms_otp” or “verify_sms_otp” 3 => hash of additional arguments if any
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/jobs/otp_job.rb', line 21 def perform(args) resource_class = args[0] resource_id = args[1] job_type = args[2] params = (args.size == 4) ? JSON.parse(args[3]).deep_symbolize_keys : nil ############### WEBHOOK JOBS ########################## if job_type == "sms_webhook" sms_webhook(params) elsif job_type == "email_webhook" email_webhook(params) end ############### JOBS THAT NEED A RESOURCE ############# if resource_class && Auth.configuration.auth_resources[resource_class] resource_class = resource_class.constantize resource = resource_class.find(resource_id) Auth::TwoFactorOtp.resource = resource if job_type == "send_sms_otp" auth_gen elsif job_type == "verify_sms_otp" verify(params[:otp]) elsif job_type == "send_transactional_sms" notification = params[:notification_class].capitalize.constantize.find(params[:notification_id]) notification.send_sms(resource) do send_transactional_sms(notification.format_for_sms(resource)) end elsif job_type == "send_email" ## so we need to specify a mailer class ## that is why it is not working here. notification = params[:notification_class].capitalize.constantize.find(params[:notification_id]) email = Auth.configuration.mailer_class.constantize.notification(resource,self) email = add_webhook_identifier_to_email(email) notification.send_email(resource) do JSON.generate(email..mailgun_variables) end email.deliver_now end end end |
#StandardError ⇒ Object
we currently log all exceptions to redis.
11 12 13 14 |
# File 'app/jobs/otp_job.rb', line 11 rescue_from(StandardError) do |exception| puts exception. puts exception.backtrace.join("\n") end |