Monitor scheduled tasks in laravel

smknstd
code16
Published in
1 min readJun 3, 2019
Photo by marc liu on Unsplash

When scheduling tasks, like database backups, silent fails are the worst. Being aware of failure of those tasks is critical. Hopefully healthcheck, an open source cron monitoring solution can help!

As a self hosted plateform or directly on their nice saas, it lets you:

  • List tasks with status and execution time
  • Get immediate alerts (email, slack, etc) when pings don’t arrive on schedule

The good part is there is pretty much no configuration at all. All you need to do is a little wiring. As recently enhanced in 5.8, laravel task hooks now let you finally plug all your scheduled stuff to an external monitoring system, through new “pingOnSuccess” method.

protected function schedule(Schedule $schedule)
{
$schedule->command('my:command')
->pingBefore('https://hc-ping.com/unique-task-id/start')
->pingOnSuccess('https://hc-ping.com/unique-task-id');
}

And you’re done !

Now every time, your task will fail or for any reason doesn’t start, you‘ll be notified (after a grace time period) through your favorite channel.

--

--