在延迟作业中运行时Twilio Rest客户端的未定义方法消息

时间:2015-09-18 15:23:14

标签: ruby-on-rails ruby ruby-on-rails-3 twilio twilio-click-to-call

我正在使用twilio gem发送消息。当我尝试直接运行函数没有任何延迟时,消息将被发送到特定的数字,但当我尝试运行延迟的作业时,我收到错误 未定义的方法`消息'对于#

我确实要求' twilio-ruby'在我的代码中,但它没有显示任何效果。

如果我尝试使用Delayed::Job.where(:id => 21501).first.invoke_job手动调用作业,它会运行而不会出现任何错误。因此,我更加困惑地想到确切错误在哪里。

TwilioBase.rb

require 'twilio-ruby'
module Common
 module Sms
  class TwilioBase < Base   

   def initialize(phone, client:, associate_with: nil)
     account_sid = twilio_settings[:account_sid]
     auth_token = twilio_settings[:auth_token]

     @twilio_object = Twilio::REST::Client.new(account_sid, auth_token)
   end      

    def call_api(query_hash)
     res = @twilio_object.account.messages.create(query_hash['query_hash'])
    end
  end 
 end
end

SmsJob.rb文件

class SmsJob
 def self.create!(sms_gateway_object, queued_sms, opts={},      delayed_job_opts={})
   q_sms = queued_sms
   sms_job = self.new(q_sms.id, sms_gateway_object, opts)
   job = Delayed::Job.enqueue(sms_job, delayed_job_opts)
   q_sms.update_attributes!({:delayed_job_id => job.id})
   return sms_job
 end


  def perform
    q = Common::QueuedSms.find(@queued_sms_id                    
    @sms_gateway_object.deliver_sms(@opts)
  end


 private
 def initialize(queued_sms_id, sms_gateway_object, opts)
   @queued_sms_id = queued_sms_id
   @opts = opts
   @sms_gateway_object = sms_gateway_object
 end
end

致电延迟工作

SmsJob.create!(self, @q_sms, deliver_sms_opts)

- 编辑 -

**这是我在延迟的工作追踪中可以看到的唯一错误**

[Worker(host:ankita-Inspiron-5520 pid:9080)] Job SmsJob (id=21501)   FAILED (4 prior attempts) with ValidationError: undefined method `messages' for #<Twilio::REST::Client:0x0000000000000>

0 个答案:

没有答案