0

I am on Rails 4 using the Resque Scheduler gem.

I am also using the sitemap generator gem in order to dynamically generate my sitemap.

I am having trouble figuring out the best way to schedule a rake task with resque scheduler. The sitemap generator recommends whenever, but I am assuming resque scheduler can accomplish the same thing (don't want to install another gem if I don't have to).

Does anyone know how to set this up?

I would like to run rake sitemap:refresh:no_ping every 5 hours.

I was thinking I would just schedule a background job and run it from there:

# resque_schedule.yml

update_sitemap:
  every: 5h
  class: "SitemapUpdater"
  description: "This job refreshes the sitemap"



# sitemap_updater.rb

class SitemapUpdater

  @queue = :sitemap_queue

  def self.perform
    # run rake task here
  end

end

... however, I'm not sure if this is a good practice. Any advice would be much appreciated.

Kathan
  • 1,428
  • 2
  • 15
  • 31
  • you better to use [linux cron](https://en.wikipedia.org/wiki/Cron). [this](https://stackoverflow.com/questions/11571789/rake-task-with-cron-job?rq=1) might help you – Martin May 21 '16 at 08:38

1 Answers1

0

I don't see a problem with your approach, you just must be aware that the scheduler is reset during every deployment, so if you do frequent deploys, your scheduled jobs might be run later or even not run at all, as documented:

IMPORTANT: Rufus every syntax will calculate jobs scheduling time starting from the moment of deploy, resulting in resetting schedule time on every deploy, so it's probably a good idea to use it only for frequent jobs (like every 10-30 minutes), otherwise - when you use something like every 20h and deploy once-twice per day - it will schedule the job for 20 hours from deploy, resulting in a job to never be run.

You might also run the rake from system cron itself, which is an even more lightweight solution as it requires no scheduler gems at all, just the rake task, and will be scheduled reliably in time.

See e.g. this answer for setting up the "every 5 hours" frequency in crontab and you might also need to study RVM wrappers if you use RVM for your ruby project (you must call rake using the RVM wrappers in such case, e.g. call /home/deploy/.rvm/wrappers/ruby-2.3.0@mygemset/rake instead of just rake).

Community
  • 1
  • 1
Matouš Borák
  • 15,606
  • 1
  • 42
  • 53