1
votes

I'm using Heroku's Scheduler add-on to run jobs in my app at scheduled time intervals, much like cron in a traditional server environment. The tasks are rather trivial, in it that they simply enqueue a sidekiq worker. However, as you can see in the photo below, :update_job_posts fails to run at 4:30UTC for some reason.

Am I not able to combine the two jobs this way, or do they need to run separately?

If I run the task with heroku run it passes. heroku run uses to execute your jobs, so you can be assured that if it works with heroku run, it will work from the scheduler.

$ 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.

Moreover, heroku logs --tail show the other tasks running:

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

Heroku Scheduler

1

1 Answers

5
votes

Known issues and alternatives

Heroku Scheduler Says On The Documentation

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

In very rare instances, a job may be skipped.

In very rare instances, a job may run twice.

I was implemented this in some cases and I noticed after some days are gone it's not working properly with background process then again read their documentation and find out this cause.

Now I have implemented sidekiq-scheduler and it's working properly.

I hope it will help.