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

Add a boolean parameter to the doNotMonitor function #88

Merged
merged 1 commit into from
May 24, 2023
Merged

Add a boolean parameter to the doNotMonitor function #88

merged 1 commit into from
May 24, 2023

Conversation

bilfeldt
Copy link
Contributor

@bilfeldt bilfeldt commented May 24, 2023

Laravel offers a conditional when function to be used for conditional registration of scheduled commands. This function accepts a closure or a boolean and that closure will be invoked every time the scheduler is running.

This conditional function can be very useful for enabling/disabling scheduled jobs via config like so:

$schedule->command('foo:bar')
    ->dailyAt('22:15')
    ->when(config('scheduled-jobs.foo-bar'));

Now it is not possible for this monitor to invoke the same closure on every scheduled job, because the system needs to know when to expect a run. But wouldn't it be nice if the same config could be used to set whether or not the command should be monitored? You can do that now with this PR 🥳

$schedule->command('foo:bar')
    ->dailyAt('22:15')
    ->when(config('scheduled-jobs.foo-bar'))
    ->doNotMonitor(! config('scheduled-jobs.foo-bar'));

@freekmurze freekmurze merged commit 1251901 into spatie:main May 24, 2023
@freekmurze
Copy link
Member

Thanks!

@bilfeldt bilfeldt deleted the features/boolean-do-not-monitor branch May 24, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants