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)
account_sid = Communify.account_sid
auth_token = Communify.auth_token
@client = Twilio::REST::Client.new account_sid, 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) 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
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}") end
end
|