Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes \Datetime to \DateTimeInterface. #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Command/ScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Console/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions Console/ScheduleInSecondInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
4 changes: 2 additions & 2 deletions Cron/CommandScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Cron/JobScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public function getExecuteAfter()
return $this->executeAfter;
}

public function setExecuteAfter(\DateTime $executeAfter)
public function setExecuteAfter(\DateTimeInterface $executeAfter)
{
$this->executeAfter = $executeAfter;
}
Expand Down
6 changes: 3 additions & 3 deletions Resources/doc/scheduled_jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down