Sidekiq异步发送重复的电子邮件

时间:2014-05-19 13:04:10

标签: ruby-on-rails asynchronous ruby-on-rails-4 actionmailer sidekiq

我正在关注本教程:http://blog.remarkablelabs.com/2013/01/using-sidekiq-to-send-emails-asynchronously以异步方式发送电子邮件。一切正常,但电子邮件发送两次。我检查了控制台,它创建了1个作业,但这个作业发送了两次,每次发送相同的电子邮件。我发送电子邮件的方法是:

def high_value_filter
  if self.branch.vendor.high_value.to_i <= self.spent_value.to_i
    Alert.create(:table => "transactions", :item_id => self.id, :type_id => Alert::Type::TRANSACTION_HIGH_VALUE)
    ## Sent emails assynchronously if Redis connected
    if redis_connected?
      #MyMailer.delay.high_spent_value(self.branch ,self.consumer, self, self.current_user, self.host)
      MyMailer.delay.high_spent_value(self.branch ,self.consumer, self, self.current_user, self.host, self.branch.email) if self.branch.email.present? 
    else
      MyMailer.high_spent_value(self.branch ,self.consumer, self, self.current_user, self.host)
      MyMailer.high_spent_value(self.branch ,self.consumer, self, self.current_user, self.host, self.branch.email) if self.branch.email.present?
    end
  end
end

我的邮件是:

def high_spent_value(branch ,consumer, transaction, current_user, host, receiver = "email@hotmail.com")
  @branch = branch
  @consumer = consumer
  @transaction = transaction
  @user = current_user
  @host = host
  mail(to: receiver, subject: "Valor alto gasto em #{@branch.vendor.name}").deliver
end

OBS:我尝试删除传递方法,但复制仍然存在,请问某人现在发生了什么?

0 个答案:

没有答案