-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add laravel 8 support. Simplify usage
- Loading branch information
Roman Nagirnyi
committed
Dec 3, 2020
1 parent
72e5c89
commit 7af3436
Showing
6 changed files
with
74 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace TheRezor\DatabaseSchedule\Scheduling; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Console\Scheduling\Schedule as BaseSchedule; | ||
|
||
class Schedule extends BaseSchedule | ||
{ | ||
protected $isScheduleAdded = false; | ||
|
||
public function dueEvents($app) | ||
{ | ||
if ($this->isScheduleAdded) { | ||
return parent::dueEvents($app); | ||
} | ||
|
||
$model = $app->make(Config::get('database-schedule.model')); | ||
$schedules = Config::get('database-schedule.cache.enabled') ? $this->getFromCache($model) : $model->all()->toArray(); | ||
|
||
foreach ($schedules as $s) { | ||
$event = $this->command($s['command'], $s['params'])->cron($s['expression']); | ||
|
||
if ($s['even_in_maintenance_mode']) { | ||
$event->evenInMaintenanceMode(); | ||
} | ||
|
||
if ($s['without_overlapping']) { | ||
$event->withoutOverlapping(); | ||
} | ||
} | ||
|
||
return parent::dueEvents($app); | ||
} | ||
|
||
protected function getFromCache(Model $model) | ||
{ | ||
$store = Config::get('database-schedule.cache.store', 'file'); | ||
$key = Config::get('database-schedule.cache.key', 'database_schedule'); | ||
|
||
return Cache::store($store)->rememberForever($key, function () use ($model) { | ||
return $model->all()->toArray(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters