Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron monitoring improvements #677

Merged
merged 2 commits into from
Jun 29, 2023
Merged

Cron monitoring improvements #677

merged 2 commits into from
Jun 29, 2023

Conversation

stayallive
Copy link
Collaborator

@stayallive stayallive commented Apr 5, 2023

Making use of the new cron monitoring upsert possibilities we can add some information to automatically create a cron monitor by "simply" scheduling an command and calling ->sentryMonitor() on it.

    protected function schedule(Schedule $schedule): void
    {
        $schedule->command(MyCommand::class)->everyMinute()->sentryMonitor();
    }

The sentryMonitor method has a few (all optional) arguments:

->sentryMonitor(
    monitorSlug: null,         // you can set a custom slug here, needed for crons created from UI or duplicated scheduled commands (same command scheduled more than once)
    checkInMargin: 60,         // amount of seconds (?) the command is allowed to be late to check in
    maxRuntime: 300,           // amount of seconds (?) the command is allowed to run
    updateMonitorConfig: true, // indicates if we should send the monitor config with the checking to update the schedule and other config automatically (can be disabled in case you want control over it in the UI
)

Would be nice to have:

  • Upsert the cron name instead of it being set equal to the slug (is this possible?)

This depends on the release of:

@stayallive stayallive marked this pull request as ready for review June 23, 2023 20:59
@stayallive stayallive requested a review from cleptric June 23, 2023 21:00
Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Will get the docs ready then.

@cleptric cleptric merged commit 3c5b835 into master Jun 29, 2023
@cleptric cleptric deleted the cron-improvements branch June 29, 2023 09:35
@ankurk91
Copy link
Contributor

This is how i was able to monitor app of my schedule tasks

<?php

namespace App\Providers;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\ServiceProvider;

class CronMonitorProvider extends ServiceProvider
{
    public function boot(): void
    {
        if (!$this->app->runningInConsole()) {
            return;
        }

        $this->app->booted(fn() => $this->hookMonitor());
    }

    protected function hookMonitor(): void
    {
        $events = $this->app->make(Schedule::class)->events();

        foreach ($events as $event) {
            if ($event->hasMacro('sentryMonitor')) {
                $event->sentryMonitor();
            }
        }
    }
}

@stayallive
Copy link
Collaborator Author

@ankurk91 ah, that is a smart one to hook all your scheduled events at once, nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants