diff --git a/Command/ScheduleCommand.php b/Command/ScheduleCommand.php index fa6fe57a..c0574cfa 100644 --- a/Command/ScheduleCommand.php +++ b/Command/ScheduleCommand.php @@ -100,7 +100,7 @@ private function scheduleJobs(OutputInterface $output, ManagerRegistry $registry } } - private function acquireLock(ManagerRegistry $registry, $commandName, \DateTime $lastRunAt) + private function acquireLock(ManagerRegistry $registry, $commandName, \DateTimeInterface $lastRunAt) { /** @var EntityManager $em */ $em = $registry->getManagerForClass(CronJob::class); diff --git a/Console/CronCommand.php b/Console/CronCommand.php index 8dc952ea..3092d2e8 100644 --- a/Console/CronCommand.php +++ b/Console/CronCommand.php @@ -9,10 +9,10 @@ interface CronCommand /** * @return Job */ - public function createCronJob(\DateTime $lastRunAt); + public function createCronJob(\DateTimeInterface $lastRunAt); /** * @return boolean */ - public function shouldBeScheduled(\DateTime $lastRunAt); + public function shouldBeScheduled(\DateTimeInterface $lastRunAt); } \ No newline at end of file diff --git a/Console/ScheduleInSecondInterval.php b/Console/ScheduleInSecondInterval.php index bf868375..1a6e2bea 100644 --- a/Console/ScheduleInSecondInterval.php +++ b/Console/ScheduleInSecondInterval.php @@ -7,12 +7,12 @@ trait ScheduleInSecondInterval { - public function shouldBeScheduled(\DateTime $lastRunAt) + public function shouldBeScheduled(\DateTimeInterface $lastRunAt) { return time() - $lastRunAt->getTimestamp() >= $this->getScheduleInterval(); } - public function createCronJob(\DateTime $_) + public function createCronJob(\DateTimeInterface $_) { if ( ! $this instanceof Command) { throw new \LogicException('This trait must be used in Symfony console commands only.'); diff --git a/Cron/CommandScheduler.php b/Cron/CommandScheduler.php index 106485b0..8d8eaa1e 100644 --- a/Cron/CommandScheduler.php +++ b/Cron/CommandScheduler.php @@ -13,12 +13,12 @@ public function __construct(CronCommand $command) $this->command = $command; } - public function shouldSchedule($_, \DateTime $lastRunAt) + public function shouldSchedule($_, \DateTimeInterface $lastRunAt) { return $this->command->shouldBeScheduled($lastRunAt); } - public function createJob($_, \DateTime $lastRunAt) + public function createJob($_, \DateTimeInterface $lastRunAt) { return $this->command->createCronJob($lastRunAt); } diff --git a/Cron/JobScheduler.php b/Cron/JobScheduler.php index f4a55caf..957b0beb 100644 --- a/Cron/JobScheduler.php +++ b/Cron/JobScheduler.php @@ -9,10 +9,10 @@ interface JobScheduler /** * @return boolean */ - public function shouldSchedule($command, \DateTime $lastRunAt); + public function shouldSchedule($command, \DateTimeInterface $lastRunAt); /** * @return Job */ - public function createJob($command, \DateTime $lastRunAt); + public function createJob($command, \DateTimeInterface $lastRunAt); } \ No newline at end of file diff --git a/Entity/Job.php b/Entity/Job.php index ccfd6aa9..2fb2538c 100644 --- a/Entity/Job.php +++ b/Entity/Job.php @@ -352,7 +352,7 @@ public function getExecuteAfter() return $this->executeAfter; } - public function setExecuteAfter(\DateTime $executeAfter) + public function setExecuteAfter(\DateTimeInterface $executeAfter) { $this->executeAfter = $executeAfter; } diff --git a/Resources/doc/scheduled_jobs.rst b/Resources/doc/scheduled_jobs.rst index 19b9d63d..d267f621 100644 --- a/Resources/doc/scheduled_jobs.rst +++ b/Resources/doc/scheduled_jobs.rst @@ -17,12 +17,12 @@ Implement CronCommand { // configure, execute, etc. ... - public function shouldBeScheduled(\DateTime $lastRunAt) + public function shouldBeScheduled(\DateTimeInterface $lastRunAt) { return time() - $lastRunAt->getTimestamp() >= 60; // Executed at most every minute. } - public function createCronJob(\DateTime $lastRunAt) + public function createCronJob(\DateTimeInterface $lastRunAt) { return new Job('my-scheduled-command'); } @@ -54,7 +54,7 @@ This is useful if you want to run a third-party command or a Symfony command as */ class MyJobScheduler implements JobScheduler { - public function shouldSchedule($commandName, \DateTime $lastRunAt) + public function shouldSchedule($commandName, \DateTimeInterface $lastRunAt) { return time() - $lastRunAt->getTimestamp() >= 60; // Executed at most every minute. } diff --git a/Tests/Functional/TestBundle/Command/ScheduledEveryFewSecondsCommand.php b/Tests/Functional/TestBundle/Command/ScheduledEveryFewSecondsCommand.php index e3c563a6..b3f1472e 100644 --- a/Tests/Functional/TestBundle/Command/ScheduledEveryFewSecondsCommand.php +++ b/Tests/Functional/TestBundle/Command/ScheduledEveryFewSecondsCommand.php @@ -10,12 +10,12 @@ class ScheduledEveryFewSecondsCommand extends ContainerAwareCommand implements CronCommand { - public function shouldBeScheduled(\DateTime $lastRunAt) + public function shouldBeScheduled(\DateTimeInterface $lastRunAt) { return time() - $lastRunAt->getTimestamp() >= 5; } - public function createCronJob(\DateTime $_) + public function createCronJob(\DateTimeInterface $_) { return new Job('scheduled-every-few-seconds'); }