diff --git a/README.md b/README.md index fdc58cf..2d87c01 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/snooze.php b/config/snooze.php index 44111ad..f3e8d17 100644 --- a/config/snooze.php +++ b/config/snooze.php @@ -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), ]; diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 8c1fb88..ea16c94 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -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();