composer require "synergitech/cronitor-laravel"
- Laravel 6.x-8.x
- PHP 7.3-7.4, 8.0
php artisan vendor:publish --provider="SynergiTech\Cronitor\Laravel\CronitorServiceProvider"
Your Jobs can be automatically monitored by this package by implementing the HasCronitorKey
contract.
use SynergiTech\Cronitor\Laravel\Contracts\HasCronitorKey;
class YourJob implements HasCronitorKey
{
public function getMonitorKey(): string
{
return 'your monitor key from cronitor.io';
}
}
When your Job is dispatched, a Dispatcher middleware will automatically send telemetry events based on whether your job is successful.
Additionally, you can monitor any callback via the Cronitor
facade:
use SynergiTech\Cronitor\Laravel\Facades\Cronitor;
class YourClass
{
public function handle()
{
Cronitor::monitorJob('your monitor key', function () {
throw new \Exception('This will automatically be reported as a fail event');
});
}
}