completed SMS gateway project
This commit is contained in:
22
app/jobs/retry_failed_sms_job.rb
Normal file
22
app/jobs/retry_failed_sms_job.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class RetryFailedSmsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(sms_message_id)
|
||||
sms = SmsMessage.find(sms_message_id)
|
||||
|
||||
# Only retry if message can be retried
|
||||
return unless sms.can_retry?
|
||||
|
||||
# Reset status to queued and increment retry count
|
||||
sms.increment_retry!
|
||||
sms.update!(status: "queued", error_message: nil)
|
||||
|
||||
# Re-queue for sending with exponential backoff
|
||||
wait_time = (2 ** sms.retry_count).minutes
|
||||
SendSmsJob.set(wait: wait_time).perform_later(sms.id)
|
||||
|
||||
Rails.logger.info("Retrying failed SMS #{sms.message_id} (attempt #{sms.retry_count})")
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
Rails.logger.error("SMS message not found: #{e.message}")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user