Skip to content

Commit

Permalink
Merge pull request #14 from cesargb/scheduler
Browse files Browse the repository at this point in the history
update register schedule
  • Loading branch information
cesargb authored Oct 10, 2021
2 parents a17b9fb + fa9ffae commit 4a4683f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"license": "MIT",
"require": {
"php" : "^7.2 | ^8.0",
"illuminate/config": "^6.0|^7.0|^8.0",
"illuminate/console": "^6.0|^7.0|^8.0",
"illuminate/log": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0",
"illuminate/config": "^6.10|^7.0|^8.0",
"illuminate/console": "^6.10|^7.0|^8.0",
"illuminate/log": "^6.10|^7.0|^8.0",
"illuminate/support": "^6.10|^7.0|^8.0",
"monolog/monolog": "^2.0"
},
"require-dev": {
"orchestra/testbench": "^4.0|^5.0|^6.0",
"orchestra/testbench": "^4.10|^5.0|^6.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"autoload": {
Expand Down
27 changes: 16 additions & 11 deletions src/RotateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,9 @@ public function boot()
Commands\Rotate::class,
Commands\RotateFile::class,
]);
}

$this->app->booted(function () {
if (config('rotate.schedule.enable', true)) {
$schedule = $this->app->make(Schedule::class);

$cronOldVersion = config('rotate.logs_rotate_schedule', '0 0 * * *');
$cron = config('rotate.schedule.cron', $cronOldVersion);

$schedule->command('rotate:logs')->cron($cron);
}
});
$this->registerSchedule();
}
}

/**
Expand All @@ -46,4 +37,18 @@ public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/rotate.php', 'rotate');
}

private function registerSchedule()
{
if (! config('rotate.schedule.enable', true)) {
return;
}

$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
$cronOldVersion = config('rotate.logs_rotate_schedule', '0 0 * * *');
$cron = config('rotate.schedule.cron', $cronOldVersion);

$schedule->command('rotate:logs')->cron($cron);
});
}
}

0 comments on commit 4a4683f

Please sign in to comment.