Skip to content

implement queue release delay #6

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

Merged
merged 2 commits into from
Mar 13, 2018
Merged
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
15 changes: 10 additions & 5 deletions src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Interop\Queue\PsrConsumer;
use Interop\Queue\PsrContext;
use Interop\Queue\PsrMessage;
use Interop\Queue\DeliveryDelayNotSupportedException;

class Job extends BaseJob implements JobContract
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public function __construct(Container $container, PsrContext $psrContext, PsrCon
$this->psrMessage = $psrMessage;
$this->connectionName = $connectionName;
}

public function getJobId()
{
return $this->psrMessage->getMessageId();
Expand All @@ -62,16 +63,20 @@ public function delete()
*/
public function release($delay = 0)
{
if ($delay) {
throw new \LogicException('To be implemented');
}
parent::release($delay);

$requeueMessage = clone $this->psrMessage;
$requeueMessage->setProperty('x-attempts', $this->attempts() + 1);

$this->psrContext->createProducer()->send($this->psrConsumer->getQueue(), $requeueMessage);
$producer = $this->psrContext->createProducer();

try {
$producer->setDeliveryDelay($this->secondsUntil($delay) * 1000);
} catch (DeliveryDelayNotSupportedException $e) {
}

$this->psrConsumer->acknowledge($this->psrMessage);
$producer->send($this->psrConsumer->getQueue(), $requeueMessage);
}

/**
Expand Down