Running Cron Tasks on Heroku

前端 未结 6 754
情书的邮戳
情书的邮戳 2020-12-05 03:06

I\'ve seen that Heroku charges $15/mo to run Delayed Job, and $3/mo to run cron tasks daily. Is it possible to skip that entirely and run my own cron tasks manually? Or ar

6条回答
  •  情书的邮戳
    2020-12-05 03:22

    If you install the Heroku gem on your computer, you can then run your cron tasks manually as follows:

    $ heroku rake cron
    (in /disk1/home/slugs/xxxxxx_aa515b2_6c4f/mnt)
    Running cron at 2010/04/25 10:28:54...
    

    This will execute the exact same code as Heroku's daily/hourly cron add-on does; that is, for this to work, your application must have a Rakefile with a cron task, for example:

    desc "Runs cron maintenance tasks."
    task :cron do
      puts "Running cron at #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}..."
      # TODO: your cron code goes here
    end
    

    Now, just add the heroku rake cron command to a crontab on any Unix server of yours, or even directly to your personal computer's crontab if you're running Linux or Mac OS X, and you can be scheduling cron jobs for your Heroku application as you please and without being charged for it.

提交回复
热议问题