Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Laravel 5's task scheduling in Heroku?

I'm trying to follow the Laravel Documentation on how to Run Cron Jobs, and I want to add this

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

But I don't know how to add it to Heroku.

like image 673
user2099451 Avatar asked Feb 02 '16 10:02

user2099451


People also ask

How do I schedule a task in Heroku?

Scheduling jobs If you want to schedule the job at a certain local time, add the proper UTC offset. For example, add rake update_feed , select “Hourly” and “:30” to update feeds every hour on the half-hour. Then add rake send_reminders , select “Daily” and “00:00” to send reminders every day at midnight.

Can you run cron jobs on Heroku?

Cron To Go is an add-on created for Heroku users to run scheduled jobs based on one-off dynos using cron expressions.

How does Laravel task scheduling work?

The scheduler allows you to fluently and expressively define your command schedule within your Laravel application itself. When using the scheduler, only a single cron entry is needed on your server. Your task schedule is defined in the app/Console/Kernel.php file's schedule method.


1 Answers

I created this Scheduler which runs once a minute and is part of your own app.

https://gist.github.com/robbydooo/65bf341ea0f4081150b945bfb1d38d3c

It creates a new Dyno type called Scheduler which you start one of.

Make sure you run jobs on your queue to avoid this scheduler over running once per minute.

To use this scheduler with Laravel 5.4+ add this file to /app/Console/Commands/RunScheduler.php Register this file in app/Console/Kernel.php

protected $commands = [
…
Commands\RunScheduler::class
…
]

Add this line to your Procfile:

scheduler: php -d memory_limit=512M artisan schedule:cron
like image 103
Robert Norman Avatar answered Oct 08 '22 17:10

Robert Norman