# Scheduled task monitoring now available to all our users

After an intense testing period, we're excited to announce our scheduled task monitoring is now available to all our users!

![Scheduled task monitoring in Oh Dear](/img/features/cron_example_listing.png)

## Why monitor scheduled tasks?

Automation is at the heart of just about every company these days. We trust our automation to do the work for us. We trust that it will continue to run fine, from the day we wrote the code.

But _trust_ isn't a strategy. It's _hope_. It's a _wish_.

With our newly launched scheduled task monitor, we can turn that _hope_ into a _certainty_. 😎

You'll be able to monitor the frequency of every scheduled task you have and get actionable reports when they either A) don't run on time or B) don't report any status, indicating the task more than likely failed.

## Free for all Oh Dear users

This feature is now live and available to all existing Oh Dear users, at no additional cost.

You'll find a new column on your dashboard called _Tasks_, with additional information available once you click through. Per site, you can add scheduled tasks and start monitoring straight away!

## How does scheduled task monitoring work?

We use an industry-standard approach in the form of "ping URLs".

The idea is quite simple: after every task gets executed, your application code can make a network request to a pre-defined URL we provide you. We monitor the requests on that URL.

If we don't receive a request (on time), we assume the scheduled task has failed, and we can notify you.

Making a network request doesn't have to be complex, for many languages it's a one-line addition to your scripts.

PHP:

```php
@file_get_contents('https://ping.ohdear.app/e536e771-9ff6');
```

Python:

```python
requests.get("https://ping.ohdear.app/e536e771-9ff6")
```

Ruby:

```ruby
Net::HTTP.get(URI.parse('https://ping.ohdear.app/e536e771-9ff6'))
```

Node:

```nodejs
https.get("https://ping.ohdear.app/e536e771-9ff6");
```

We've got [a lot of examples](/docs/features/cron-job-monitoring) available for just about any popular language.

## Deep integration into PHP

Because we have deeply nested roots in the PHP community, there are more convenient integrations available for Laravel and Symfony users.

For [Laravel](https://ohdear.app/docs/features/cron-job-monitoring#php), you can integrate using [an additional package that auto-syncs your tasks to Oh Dear](https://github.com/spatie/laravel-schedule-monitor).

```php
$ composer require spatie/laravel-schedule-monitor
$ composer require ohdearapp/ohdear-php-sdk 
$ php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="migrations"
$ php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="config"
$ php artisan migrate
```

As a final step, add your [Oh Dear API key](/docs/api/introduction) to `config/schedule-monitor.php` and this package will automatically sync all schedules to Oh Dear and we'll take it from there.

![Cron sync from Oh Dear](/uploads/blogs/scheduled-task-monitoring/sync-oh-dear.png)

Freek made a more in-depth video of how this works under the hood, if you're interested:

<iframe src="https://player.vimeo.com/video/460607656" width="640" height="480" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>

If you prefer not to use an extra package, you could add the `thenPing()` method to each of the task definitions in your `Console/Kernel.php` instead:

```php
class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('emails:send')
            ->daily()
            ->thenPing('https://ping.ohdear.app/e536e771-9ff6');
    }
}
```

For Symfony users, there's [a PingTask package](https://ohdear.app/docs/features/cron-job-monitoring#php) that allows you to define the ping URL per task you define:

```php
use Zenstruck\ScheduleBundle\Schedule\Task\PingTask;

$schedule->add(new PingTask('https://ping.ohdear.app/e536e771-9ff6'));
```

Whatever your use case may be, you'll find a convenient integration for it.

## Notifications where you need them

As with all our checks, this monitoring is coupled with our powerful notification system!

You can choose where you [receive your notifications](/features/notifications) and what _type_ of notifications you want. Only care about the failures? Just enable that.

![Example Slack notification for a failed scheduled task](/img/features/cron_slack_notification.png)

We've been using this ourselves for several months now and have included every improvement we wanted _ourselves_ into this feature. Our goal is to put all the necessary information right at your fingertips.

## Cron jobs & scheduled task monitoring

We call the feature _"scheduled task monitoring"_, but it's more than just that. _Anything_ can be a scheduled task.

From a cron job that calls a back-up script to a scheduled task on Windows, everything that _should_ run on a fixed schedule can be monitored through this new feature.

For instance, you can monitor the successes of your back-up script that is triggered via cron:

```bash
24 4 * * * /root/tarsnap-backup.sh && curl -fsS --retry 3 -o /dev/null https://ping.ohdear.app/e536e771-9ff6
```

Because of the use of the `&&` operator, the `curl` example will _only_ be executed if the first script exited with an exit code of `0`, to indicate it succeeded. If it reports anything else, the `curl` won't be called and we will know we missed a report for that task.

## Monitoring queues and jobs health

Since the idea behind _scheduled task monitoring_ is to check a URL for recurring hits, this can also be used to monitor the health of running jobs or queues.

Imagine the following flow:

1. Add a new scheduled task in your code to put a new job on the queue every 5 minutes
2. This job has one purpose: to ping our endpoint

This way, you've tested your application one step further: this ensures both the _schedule_ runs and the _queues_ are alive to pick up & process jobs.

If we don't receive the hit to our endpoint on time, chances are something's wrong and we can alert you.

## Want to give it a try?

Some things at Oh Dear don't change: we still have a free, 10-day trial, with no strings attached. Just an email and a password are needed, no credit card details.

[Start a trial today and see how easy it is to integrate scheduled task monitoring!](https://ohdear.app/register)

If you decide to sign up, we're giving a 30% discount for the first 3 months for any new user. Use coupon code `MONITOR-ALL-THE-THINGS` during subscription to lock in your discount. This code is valid until October 1st, 2020!

We're immensely proud of this feature ([so much goes on behind the scenes](https://freek.dev/1767-why-and-how-you-should-monitor-scheduled-tasks)) and can't wait to hear your feedback.

If we could ask a favour: share this post as far and wide as you can! 😁