99use Tempest \Console \Scheduler ;
1010use Tempest \Core \ShellExecutor ;
1111use function Tempest \event ;
12+ use function Tempest \internal_storage_path ;
1213
1314final readonly class GenericScheduler implements Scheduler
1415{
15- public const string CACHE_PATH = __DIR__ . '/../../../../.cache/tempest/last-schedule-run.cache.php ' ;
16-
1716 public function __construct (
1817 private SchedulerConfig $ config ,
1918 private ConsoleArgumentBag $ argumentBag ,
2019 private ShellExecutor $ executor ,
2120 ) {
2221 }
2322
23+ public static function getCachePath (): string
24+ {
25+ return internal_storage_path ('scheduler ' , 'last-schedule-run.cache.php ' );
26+ }
27+
2428 public function run (?DateTime $ date = null ): void
2529 {
2630 $ date ??= new DateTime ();
@@ -80,11 +84,11 @@ private function getInvocationsToRun(DateTime $date): array
8084 */
8185 private function getPreviousRuns (): array
8286 {
83- if (! file_exists (self ::CACHE_PATH )) {
87+ if (! file_exists (self ::getCachePath () )) {
8488 return [];
8589 }
8690
87- return unserialize (file_get_contents (self ::CACHE_PATH ), ['allowed_classes ' => false ]);
91+ return unserialize (file_get_contents (self ::getCachePath () ), ['allowed_classes ' => false ]);
8892 }
8993
9094 /** @param ScheduledInvocation[] $ranInvocations */
@@ -96,12 +100,12 @@ private function markInvocationsAsRun(array $ranInvocations, DateTime $ranAt): v
96100 $ lastRuns [$ invocation ->handler ->getName ()] = $ ranAt ->getTimestamp ();
97101 }
98102
99- $ directory = dirname (self ::CACHE_PATH );
103+ $ directory = dirname (self ::getCachePath () );
100104
101105 if (! is_dir ($ directory )) {
102106 mkdir (directory: $ directory , recursive: true );
103107 }
104108
105- file_put_contents (self ::CACHE_PATH , serialize ($ lastRuns ));
109+ file_put_contents (self ::getCachePath () , serialize ($ lastRuns ));
106110 }
107111}
0 commit comments