Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Cron Tasks on Heroku

Tags:

heroku

cron

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 are they somehow figuring out that I'm running cron tasks?

like image 612
Lance Avatar asked Apr 10 '10 01:04

Lance


People also ask

Can you run a cron job in Heroku?

Cron To Go is an add-on created for Heroku users to run scheduled jobs based on one-off dynos using cron expressions. Cron To Go combines the simplicity of using cron to schedule jobs with the scale and elasticity of the cloud.

Is Heroku scheduler reliable?

Reliable delivery Heroku Scheduler is a free add-on, but it doesn't guarantee that jobs will be executed at their scheduled time, or at all for that matter. While it is rare, the possibility that a job may be skipped or run twice does exist.

How do I schedule a dyno in Heroku?

Click on the Heroku Scheduler Add-on from the Resources tab on the Dashboard or run the command heroku addons:open scheduler from the CLI. Click edit on your scheduled job (usually indicated with a pencil). Under Run Command, look for a dropdown that allows you to select the dyno plan. Save Job.


2 Answers

I'm not entirely sure what you mean by "run my own cron tasks manually". For cron specifically, you need access to crontab, which they can control, as they're their servers. If you have another way of doing it, it would probably be fine, but bear in mind that your app is not tied to a specific server when running under Heroku, and that the server will change between executions.

Also, unless they've changed it since last time I checked, you can run daily cron tasks for free, but hourly costs $3/mo.

EDIT: Yes, daily crons are free. See http://addons.heroku.com/.

like image 102
Lucas Jones Avatar answered Sep 23 '22 11:09

Lucas Jones


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.

like image 44
Arto Bendiken Avatar answered Sep 20 '22 11:09

Arto Bendiken