Class: Communify::Workers::SmsWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/communify/workers/sms_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(resource_id, time, attempt) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/communify/workers/sms_worker.rb', line 11

def perform(resource_id, time, attempt)
     = Communify.
    auth_token = Communify.auth_token
    @client = Twilio::REST::Client.new , auth_token
    @current_resource = CommunifyLog.find(resource_id)
    begin
        twilio_message = @client.messages.create(from: Communify.sender_no,to: @current_resource.recipient, body: @current_resource.content) # status_callback
    rescue Exception => e
        @current_resource.update_column(:attempt_count, attempt)
        attempt = attempt +1
        @current_resource.update_column(:status, "Message failed at #{DateTime.now} due to error => #{e}")
        if attempt < 4
            sleep(time.minutes)
            retry
        end
    #end
    else
        @current_resource.update_column(:third_party_id, twilio_message.sid)
        @current_resource.update_column(:attempt_count, attempt)
        @current_resource.update_column(:status, "Message Delivered at #{DateTime.now}") #comment out
    end
end