Skip to content

Commit 4a4683f

Browse files
authored
Merge pull request #14 from cesargb/scheduler
update register schedule
2 parents a17b9fb + fa9ffae commit 4a4683f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
"license": "MIT",
2020
"require": {
2121
"php" : "^7.2 | ^8.0",
22-
"illuminate/config": "^6.0|^7.0|^8.0",
23-
"illuminate/console": "^6.0|^7.0|^8.0",
24-
"illuminate/log": "^6.0|^7.0|^8.0",
25-
"illuminate/support": "^6.0|^7.0|^8.0",
22+
"illuminate/config": "^6.10|^7.0|^8.0",
23+
"illuminate/console": "^6.10|^7.0|^8.0",
24+
"illuminate/log": "^6.10|^7.0|^8.0",
25+
"illuminate/support": "^6.10|^7.0|^8.0",
2626
"monolog/monolog": "^2.0"
2727
},
2828
"require-dev": {
29-
"orchestra/testbench": "^4.0|^5.0|^6.0",
29+
"orchestra/testbench": "^4.10|^5.0|^6.0",
3030
"phpunit/phpunit": "^7.0|^8.0|^9.0"
3131
},
3232
"autoload": {

src/RotateServiceProvider.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@ public function boot()
2323
Commands\Rotate::class,
2424
Commands\RotateFile::class,
2525
]);
26-
}
27-
28-
$this->app->booted(function () {
29-
if (config('rotate.schedule.enable', true)) {
30-
$schedule = $this->app->make(Schedule::class);
31-
32-
$cronOldVersion = config('rotate.logs_rotate_schedule', '0 0 * * *');
33-
$cron = config('rotate.schedule.cron', $cronOldVersion);
3426

35-
$schedule->command('rotate:logs')->cron($cron);
36-
}
37-
});
27+
$this->registerSchedule();
28+
}
3829
}
3930

4031
/**
@@ -46,4 +37,18 @@ public function register()
4637
{
4738
$this->mergeConfigFrom(__DIR__.'/../config/rotate.php', 'rotate');
4839
}
40+
41+
private function registerSchedule()
42+
{
43+
if (! config('rotate.schedule.enable', true)) {
44+
return;
45+
}
46+
47+
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
48+
$cronOldVersion = config('rotate.logs_rotate_schedule', '0 0 * * *');
49+
$cron = config('rotate.schedule.cron', $cronOldVersion);
50+
51+
$schedule->command('rotate:logs')->cron($cron);
52+
});
53+
}
4954
}

0 commit comments

Comments
 (0)