Heroku Scheduler 任务未达到预期 运行

Heroku Scheduler task not running as expected

我使用 Heroku 的 Scheduler 插件按预定的时间间隔在我的应用程序中执行 运行 作业,这很像传统服务器环境中的 cron。这些任务相当琐碎,因为它们只是将一个 sidekiq worker 排入队列。但是,正如您在下面的照片中看到的那样,由于某种原因 :update_job_posts 在 4:30UTC 处无法 运行。

我是否无法以这种方式合并这两项工作,还是他们需要运行 分开

如果我运行 heroku run 的任务通过。 heroku run 用于执行您的作业,因此您可以放心,如果它与 heroku 运行 一起工作,它将在调度程序中工作。

$ heroku run rake scheduler:update_job_posts
Running rake scheduler:update_job_posts on ⬢ agile-temple-76502... up, run.6604 (Free)
Updating Job feed...
I, [2018-06-06T04:40:50.341411 #4]  INFO -- : [ActiveJob] Enqueued JobFeedImportJob (Job ID: e3b9a0ed-aacb-45af-84f9-ef02acfeb85e) to Sidekiq(default)
I, [2018-06-06T04:40:50.344400 #4]  INFO -- : [ActiveJob] Enqueued RemoteFeedImportJob (Job ID: b965853d-adb3-46ee-b48d-f19306ce9d2a) to Sidekiq(default)
done.

此外,heroku logs --tail显示其他任务运行ning:

heroku[scheduler.5009]: Starting process with command `bundle exec rake scheduler:update_news_articles`
heroku[scheduler.5009]: State changed from starting to up
app[scheduler.5009]: Updating News feed...
app[scheduler.5009]: I, [2018-06-06T04:31:05.636594 #4]  INFO -- : [ActiveJob] Enqueued NewsFeedImportJob (Job ID: d672b0c5-598b-4eb7-81b6-1a0d2d8a5891) to Sidekiq(default)
app[scheduler.5009]: done.
app[worker.1]: 4 TID-tfdlg NewsFeedImportJob JID-d999a576b3193a404b3d8fdd INFO: start
app[worker.1]: I, [2018-06-06T04:31:05.636769 #4]  INFO -- : [ActiveJob] [NewsFeedImportJob] [d672b0c5-598b-4eb7-81b6-1a0d2d8a5891] Performing NewsFeedImportJob from Sidekiq(default)
heroku[scheduler.5009]: Process exited with status 0
heroku[scheduler.5009]: State changed from up to complete

scheduler.rake

namespace :scheduler do
  desc "Enqueue sidekiq job, fetches events, and creates a record for new entries"
  task :update_event_feed => :environment do
    puts "Updating Event feed..."
    EventFeedImportJob.perform_later
    puts "done."
  end

  desc "Enqueue sidekiq job, fetches job posts, and creates a record for new entries"
  task :update_job_posts => :environment do
    puts "Updating Job feed..."
    JobFeedImportJob.perform_later
    RemoteFeedImportJob.perform_later
    puts "done."
  end

  desc "Enqueue sidekiq job, fetches news articles, and creates a record for new entries"
  task :update_news_articles => :environment do
    puts "Updating News feed..."
    NewsFeedImportJob.perform_later
    puts "done."
  end
end

Known issues and alternatives

Heroku Scheduler 关于文档的说明

Scheduler is a free add-on with no guarantee that jobs will execute at their scheduled time, or at all:

在极少数情况下,可能会跳过作业。

在极少数情况下,一个工作可能 运行 两次。

我在某些情况下实现了这个,我注意到几天后它无法与后台进程一起正常工作,然后再次阅读他们的文档并找出这个原因。

现在我已经实现了 sidekiq-scheduler 并且它工作正常。

希望对您有所帮助。