我在Heroku(雪松)上运行的Rails 4.2的Ruby 2.1.6从应用程序调用(不是控制台)时,如何让ActiveJob在Heroku上的Sidekiq中排队工作?
我有Sidekiq与工头Redis的本地运行,并在我的应用我叫Rails的新ActiveJob deliver_later方法就是这样,内部application_helper.rb
:
assigning_user = User.find(object.created_by)
completing_user = User.find(object.completed_by)
if NotificationMailer.assigned_user_completed_todo(object, completing_user, assigning_user).deliver_later
nn.email_status = "sent"
end
在本地,它的工作方式与预期相同。邮件显示在'邮件程序'队列中,然后使用sendgrid进行处理和交付。
在heroku run rails console
我可以手动触发它,它工作得很好:
Loading production environment (Rails 4.2.1)
irb(main):001:0> a = Account.first
Account Load (1.5ms) SELECT "accounts".* FROM "accounts" ORDER BY "accounts"."id" ASC LIMIT 1
=> #<Account id: 1, name: "The Prestons", stripe_customer_id: nil, active_until: "2015-06-27 14:50:43", plan: nil, created_at: "2015-04-27 14:50:43", updated_at: "2015-04-27 14:50:43">
irb(main):002:0> NotificationMailer.new_account_created(a).deliver_later
Enqueued ActionMailer::DeliveryJob (Job ID: 7c0ddf9c-6892-4aa9-823e-9954b2a4e642) to Sidekiq(mailers) with arguments: "NotificationMailer", "new_account_created", "deliver_now", gid://raisin/Account/1
=> #<ActionMailer::DeliveryJob:0x007f4d9ed9da58 @arguments=["NotificationMailer", "new_account_created", "deliver_now", #<Account id: 1, name: "The Prestons", stripe_customer_id: nil, active_until: "2015-06-27 14:50:43", plan: nil, created_at: "2015-04-27 14:50:43", updated_at: "2015-04-27 14:50:43">], @job_id="7c0ddf9c-6892-4aa9-823e-9954b2a4e642", @queue_name="mailers">
但如果在我的应用我只要简单地完成动作,我想作为一个用户,没有什么是永远传递到队列的方式...我完全没有想法。我正在运行一个工作进程。我已连接到Redis云服务器。我可以看到sidekiq网页仪表板。
我没有设置什么?很高兴提供其他日志/信息,但不知道还有什么提供。
我的控制台只报告了行动:
2015-05-14T09:14:37.674095+00:00 heroku[router]: at=info method=POST path="/accounts/1/projects/15/lists/33/items/112" host=www.myapp.com request_id=516db810-8a2c-4fd0-af89-29a59783b0a8 fwd="76.104.193.78" dyno=web.1 connect=1ms service=111ms status=200 bytes=2039
你是否用'-q mailers'启动Sidekiq? –
是的 - 忘了提及。在我的proc文件中:'worker:bundle exec sidekiq -q default -q mailers' –