如何解决Heroku调度程序调用作业,但未执行
我正在用Heroku托管我的应用程序,并且在scheduler.rake
文件中有一个任务(由Heroku Scheduler调用):
task :send_recipe_summary => :environment do
puts "Calling send recipe summary slack message job..."
SendRecipeSummarySlackMessageJob.perform_later
puts "Done!"
end
(通过调度程序或在控制台中)调用此任务时,它表示该任务已排队:
➜ Plant-as-Usual-2 git:(master) heroku run bundle exec rake send_recipe_summary
Running bundle exec rake send_recipe_summary on ⬢ plant-as-usual-2... up,run.5548 (Hobby)
Calling send recipe summary slack message job...
I,[2020-09-24T16:25:50.193685 #4] INFO -- : [ActiveJob] Enqueued SendRecipeSummarySlackMessageJob (Job ID: a4110651-a9fa-4030-96ef-db4caf64c7e5) to Async(default)
Done!
但是,在日志中,作业不会排队,并且Slack消息也永远不会发送:
2020-09-24T16:25:35.913315+00:00 app[api]: Starting process with command `bundle exec rake send_recipe_summary` by user jonappleseed@email.com
2020-09-24T16:25:44.008993+00:00 heroku[run.5548]: Awaiting client
2020-09-24T16:25:44.039520+00:00 heroku[run.5548]: State changed from starting to up
2020-09-24T16:25:44.291580+00:00 heroku[run.5548]: Starting process with command `bundle exec rake send_recipe_summary`
2020-09-24T16:25:49.334067+00:00 app[worker.1]: D,[2020-09-24T16:25:49.333949 #4] DEBUG -- : [1m[36mDelayed::Backend::ActiveRecord::Job Load (1.5ms)[0m [1m[37mUPDATE "delayed_jobs" SET locked_at = '2020-09-24 16:25:49.331558',locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2020-09-24 16:25:49.330595' AND (locked_at IS NULL OR locked_at < '2020-09-24 12:25:49.330627') OR locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4') AND failed_at IS NULL) ORDER BY priority ASC,run_at ASC LIMIT 1 FOR UPDATE) RETURNING *[0m
2020-09-24T16:25:53.372387+00:00 heroku[run.5548]: Process exited with status 0
2020-09-24T16:25:53.407641+00:00 heroku[run.5548]: State changed from up to complete
2020-09-24T16:26:49.394474+00:00 app[worker.1]: D,[2020-09-24T16:26:49.394376 #4] DEBUG -- : [1m[36mDelayed::Backend::ActiveRecord::Job Load (1.5ms)[0m [1m[37mUPDATE "delayed_jobs" SET locked_at = '2020-09-24 16:26:49.392377',locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2020-09-24 16:26:49.391803' AND (locked_at IS NULL OR locked_at < '2020-09-24 12:26:49.391827') OR locked_by = 'host:9b1fc7b1-4107-427f-8f49-f058b41b7906 pid:4') AND failed_at IS NULL) ORDER BY priority ASC,run_at ASC LIMIT 1 FOR UPDATE) RETURNING *[0m
但是,如果我自己运行作业(而不是任务),那么一切都会按预期进行,并且消息确实会发送:
irb(main):002:0> SendRecipeSummarySlackMessageJob.perform_later
I,[2020-09-24T16:22:45.268729 #4] INFO -- : [ActiveJob] Enqueued SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) to Async(default)
=> #<SendRecipeSummarySlackMessageJob:0x000055b1a768dfb8 @arguments=[],@job_id="8285bb7f-9646-42bb-9901-8d219ca1175c",@queue_name="default",@priority=nil,@executions=0,@exception_executions={},@provider_job_id="c41cedd7-e5a5-4a7d-9e64-280d2ec81e1e">
irb(main):003:0> I,[2020-09-24T16:22:45.269348 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Performing SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) from Async(default) enqueued at 2020-09-24T16:22:45Z
D,[2020-09-24T16:22:46.412105 #4] DEBUG -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] (1.5ms) SELECT COUNT(*) FROM "recipes" WHERE "recipes"."state" = $1 [["state","awaiting_approval"]]
D,[2020-09-24T16:22:46.413683 #4] DEBUG -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] (1.0ms) SELECT COUNT(*) FROM "recipes" WHERE "recipes"."state" = $1 [["state","incomplete"]]
I,[2020-09-24T16:22:46.415123 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Enqueued SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) to Async(default) with arguments: "There are no recipes awaiting approval,and 1 incomplete recipe https://www.plantasusual.com/admin",{:nature=>"inform"}
I,[2020-09-24T16:22:46.415260 #4] INFO -- : [ActiveJob] [SendRecipeSummarySlackMessageJob] [8285bb7f-9646-42bb-9901-8d219ca1175c] Performed SendRecipeSummarySlackMessageJob (Job ID: 8285bb7f-9646-42bb-9901-8d219ca1175c) from Async(default) in 1145.43ms
I,[2020-09-24T16:22:46.415882 #4] INFO -- : [ActiveJob] [SendSlackMessageJob] [c640b706-9920-4639-a1a0-4c7dbec15c39] Performing SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) from Async(default) enqueued at 2020-09-24T16:22:46Z with arguments: "There are no recipes awaiting approval,[2020-09-24T16:22:46.591446 #4] INFO -- : [ActiveJob] [SendSlackMessageJob] [c640b706-9920-4639-a1a0-4c7dbec15c39] Performed SendSlackMessageJob (Job ID: c640b706-9920-4639-a1a0-4c7dbec15c39) from Async(default) in 175.12ms
有人可以帮助我理解为什么从控制台运行时作业能按预期运行,但是从调度程序运行时却无法正常工作吗?
感谢任何可以提供帮助的人!
解决方法
似乎您尚未在heroku bundle exec rake jobs:work
上启用worker。
这是一项付费服务。转到:your_app>“资源”选项卡,然后从那里启用它。 this link could be helpful
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。