Skip to content

Commit

Permalink
Feature/disable scheduling (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: atymic <[email protected]>
  • Loading branch information
gborcherds and atymic authored Jun 28, 2021
1 parent 512fb64 commit b938359
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public function shouldInterrupt($notifiable) {

If this method is not present on your notification, the notification will *not* be interrupted. Consider creating a shouldInterupt trait if you'd like to repeat conditional logic on groups of notifications.

**Conditionally turn off scheduler**

If you would like to disable sending of scheduled notifications, set an env variable of `SCHEDULED_NOTIFICATIONS_DISABLED` to `true`. You will still be able to schedule notifications, and they will be sent once the scheduler is enabled.

This could be useful for ensuring that scheduled notifications are only sent by a specific server, for example.

## Running the Tests

```bash
Expand Down
8 changes: 8 additions & 0 deletions config/snooze.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@
* If set to null, pruning will be turned off. By default it's turned off
*/
'pruneAge' => env('SCHEDULED_NOTIFICATION_PRUNE_AGE', null),

/*
* Disable sending of scheduled notifications
* You will still be able to schedule notifications,
* and they will be sent once the scheduler is enabled.
*/

'disabled' => env('SCHEDULED_NOTIFICATIONS_DISABLED', false),
];
8 changes: 5 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public function boot()
{
// Schedule base command to run every minute
$this->app->booted(function () {
$frequency = config('snooze.sendFrequency', 'everyMinute');
$schedule = $this->app->make(Schedule::class);
$schedule->command('snooze:send')->{$frequency}();
if (! config('snooze.disabled')) {
$frequency = config('snooze.sendFrequency', 'everyMinute');
$schedule = $this->app->make(Schedule::class);
$schedule->command('snooze:send')->{$frequency}();
}

if (config('snooze.pruneAge') !== null) {
$schedule->command('snooze:prune')->daily();
Expand Down

0 comments on commit b938359

Please sign in to comment.