我有这个 Sidekiq 工人:
class DealNoteWorker
include Sidekiq::Worker
sidekiq_options queue: :email
def perform(options = {})
if options[:type] == "deal_watch_mailer"
deal_watchers = DealWatcher.where("deal_id = ?", options[:deal_id])
deal_note = DealNote.find(options[:deal_note_id])
current_user = User.find(options[:current_user_id])
deal_watchers.each do |deal_watcher|
unless deal_watcher.user_id == options[:current_user_id]
# Tell the DealWatchMailer to send emails to ALL watchers advising of change to deal
if deal_watcher.user.active
DealWatchMailer.deal_watch_email(deal_watcher, nil, deal_note, current_user, options[:url]).deliver
end
end
end
elsif options[:type] == "deal_note_mailer"
options[:user_ids].each do |id|
if DealWatcher.where("deal_id = ? and user_id =?", options[:deal_id], id).count == 0
deal_note = Deal.find(options[:deal_note_id])
user = User.find_by_id(id)
DealNoteMailer.deal_note_email(deal_note, user, options[:url]).deliver
end
end
end
end
end
我将哈希传递给该perform_async
方法,但我认为传递给该perform
方法的参数与传递给的参数类型不同perform_async
。我尝试使用logger.info
并p
调试我的问题,但没有输出任何内容......
问题是该作业已添加到电子邮件队列中,但从未得到处理。我什至试图在方法中引发异常perform
(在方法的第一行),但也没有输出任何内容......
我知道以下工作人员在工作:
class DealNoteWorker
include Sidekiq::Worker
def perform(deal_id, deal_note_id, current_user_id, url)
deal_watchers = DealWatcher.where("deal_id = ?", deal_id)
deal_note = DealNote.find(deal_note_id)
current_user = User.find(current_user_id)
deal_watchers.each do |deal_watcher|
unless deal_watcher.user_id == current_user_id
# Tell the DealWatchMailer to send emails to ALL watchers advising of change to deal
if deal_watcher.user.active
DealWatchMailer.deal_watch_email(deal_watcher, nil, deal_note, current_user, url).deliver
end
end
end
end
end
所以问题出在哈希参数(选项)上。请问我做错了什么?