spatie/laravel-schedule-monitor

Support environments() on scheduled task definition

joekeilty-oub opened this issue · 0 comments

Hey there, first of all thanks for your package it is very helpful.

I have a feature request to support the environments option when defining a scheduled task.

With the setup:

.env

APP_ENV=staging

Kernel.php

protected function schedule(Schedule $schedule): void
{
    $schedule->command('normalcommand')->daily();
    $schedule->command('important-prod-only-command')->environments(['production'])->hourly();
}

When running schedule-monitor:sync and schedule-monitor:list on the staging environment, I'd expect only to monitor one command (normalcommand) especially if using OhDear integration, but it actually adds both of the commands even though we've constrained the second one to the production environment. This can lead to developer confusion, unexpected behaviour and potentially false positives on OhDear alerts

A workaround for this is to not use environments option and wrap the scheduled task definitions in if (App::environment() === 'production') etc. checks, but I find using ->environments() is a lot cleaner and saves duplication of code.

The Event class has a runsInEnvironment() method which could support this behaviour