我有这个Sidekiq工人: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
所以问题在于散列参数(选项)。请问我做错了什么?
你确定你已经开始sidekiq工人?在另一个终端中运行'bundle exec sidekiq'。另外,你正在使用一个名为'email'的队列,所以你需要运行'sidekiq -q email'。 –
是的,这是问题所在。我需要用电子邮件队列启动sidekiq。所以我在sidekiq.yml配置文件中添加了一个队列列表,解决了这个问题。你可以添加你的评论作为答案,以便我可以接受它吗? –