我在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' –