Class: SmsWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- SmsWorker
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/sms_worker.rb
Overview
This class is purely just responsible to send sms just need phone number and message when this class has failed to send a message, it will retrying to send again using different provider by executing [RecheckSmsWorker]
Defined Under Namespace
Classes: MySmsError
Constant Summary collapse
- ACTIVE_SMS_PROVIDERS =
%i[alibaba kaleyra].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#perform(msg, phones, reservation_id = nil, provider = nil) ⇒ void
Performs the task of sending an SMS message to multiple phone numbers using a chosen SMS provider.
Methods inherited from ApplicationWorker
Class Method Details
.notify_password_changed(new_password, phone) ⇒ Object
106 107 108 109 |
# File 'app/workers/sms_worker.rb', line 106 def notify_password_changed(new_password, phone) msg = "(Hungry Hub) Your new password is #{new_password}" SmsWorker.perform_async msg, phone end |
Instance Method Details
#perform(msg, phones, reservation_id = nil, provider = nil) ⇒ void
This method returns an undefined value.
Performs the task of sending an SMS message to multiple phone numbers using a chosen SMS provider.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/workers/sms_worker.rb', line 25 def perform(msg, phones, reservation_id = nil, provider = nil) return unless valid_to_send_sms?(phones, reservation_id) BUSINESS_LOGGER.set_business_context({ reservation_id: reservation_id }) if reservation_id.present? BUSINESS_LOGGER.info('SmsWorker perform', message: msg, phone_numbers: phones, provider: provider) Rails.logger.debug("Send SMS #{msg}") if Rails.env.development? phones, msg = (phones, msg) sms_provider = decide_sms_provider(provider) if sms_provider.present? sms_service_provider = decide_sms_service_provider(sms_provider) sms_service_provider.send_sms(msg, phones, reservation_id) else BUSINESS_LOGGER.info('Fail to send SMS, invalid phone number', reservation_id: reservation_id, message: msg, phone_numbers: phones) end end |