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

[5.5] WIP | Let queue handle DateInterval and DateTimeInterface. #20102

Merged
merged 1 commit into from
Jul 17, 2017
Merged
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
4 changes: 2 additions & 2 deletions src/Illuminate/Bus/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait Queueable
/**
* The number of seconds before the job should be made available.
*
* @var \DateTime|int|null
* @var \DateTimeInterface|\DateInterval|int|null
*/
public $delay;

Expand Down Expand Up @@ -61,7 +61,7 @@ public function onQueue($queue)
/**
* Set the desired delay for the job.
*
* @param \DateTime|int|null $delay
* @param \DateTimeInterface|\Da|int|null $delay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasmichot can you fix this docblock in the other PR? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed - see #20103

* @return $this
*/
public function delay($delay)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Mail/MailQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function queue($view, $queue = null);
/**
* Queue a new e-mail message for sending after (n) seconds.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|array|MailableContract $view
* @param string $queue
* @return mixed
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Contracts/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function pushRaw($payload, $queue = null, array $options = []);
/**
* Push a new job onto the queue after a delay.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @param string $queue
Expand All @@ -57,7 +57,7 @@ public function later($delay, $job, $data = '', $queue = null);
* Push a new job onto the queue after a delay.
*
* @param string $queue
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @return mixed
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function queue(Queue $queue)
/**
* Deliver the queued message after the given delay.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param Queue $queue
* @return mixed
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function queueOn($queue, $view)
/**
* Queue a new e-mail message for sending after (n) seconds.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|array|MailableContract $view
* @param string|null $queue
* @return mixed
Expand All @@ -404,7 +404,7 @@ public function later($delay, $view, $queue = null)
* Queue a new e-mail message for sending after (n) seconds on the given queue.
*
* @param string $queue
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|array $view
* @return mixed
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/PendingMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function queue(Mailable $mailable)
/**
* Deliver the queued message after the given delay.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param Mailable $mailable
* @return mixed
*/
Expand Down
25 changes: 23 additions & 2 deletions src/Illuminate/Queue/InteractsWithTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Queue;

use DateTime;
use DateInterval;
use DateTimeInterface;
use Illuminate\Support\Carbon;

Expand All @@ -10,11 +12,13 @@ trait InteractsWithTime
/**
* Get the number of seconds until the given DateTime.
*
* @param \DateTimeInterface $delay
* @param \DateTimeInterface|\DateInterval $delay
* @return int
*/
protected function secondsUntil($delay)
{
$delay = $this->handlesInterval($delay);

return $delay instanceof DateTimeInterface
? max(0, $delay->getTimestamp() - $this->currentTime())
: (int) $delay;
Expand All @@ -23,16 +27,33 @@ protected function secondsUntil($delay)
/**
* Get the "available at" UNIX timestamp.
*
* @param \DateTimeInterface|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @return int
*/
protected function availableAt($delay = 0)
{
$delay = $this->handlesInterval($delay);

return $delay instanceof DateTimeInterface
? $delay->getTimestamp()
: Carbon::now()->addSeconds($delay)->getTimestamp();
}

/**
* Converts an interval to a DateTime instance.
*
* @param \DateTimeInterface|\DateInterval|int
* @return \DateTime
*/
protected function handlesInterval($delay)
{
if ($delay instanceof DateInterval) {
$delay = (new DateTime)->add($delay);
}

return $delay;
}

/**
* Get the current system time as a UNIX timestamp.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/SqsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
/**
* Push a new job onto the queue after a delay.
*
* @param \DateTime|int $delay
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @param string $queue
Expand Down