Skip to content

Commit 0bc9cd1

Browse files
authored
Merge pull request #6 from chocopowwwa/patch-2
implement queue release delay
2 parents 6742995 + d180336 commit 0bc9cd1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Job.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Interop\Queue\PsrConsumer;
99
use Interop\Queue\PsrContext;
1010
use Interop\Queue\PsrMessage;
11+
use Interop\Queue\DeliveryDelayNotSupportedException;
1112

1213
class Job extends BaseJob implements JobContract
1314
{
@@ -41,7 +42,7 @@ public function __construct(Container $container, PsrContext $psrContext, PsrCon
4142
$this->psrMessage = $psrMessage;
4243
$this->connectionName = $connectionName;
4344
}
44-
45+
4546
public function getJobId()
4647
{
4748
return $this->psrMessage->getMessageId();
@@ -62,16 +63,20 @@ public function delete()
6263
*/
6364
public function release($delay = 0)
6465
{
65-
if ($delay) {
66-
throw new \LogicException('To be implemented');
67-
}
66+
parent::release($delay);
6867

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

72-
$this->psrContext->createProducer()->send($this->psrConsumer->getQueue(), $requeueMessage);
71+
$producer = $this->psrContext->createProducer();
72+
73+
try {
74+
$producer->setDeliveryDelay($this->secondsUntil($delay) * 1000);
75+
} catch (DeliveryDelayNotSupportedException $e) {
76+
}
7377

7478
$this->psrConsumer->acknowledge($this->psrMessage);
79+
$producer->send($this->psrConsumer->getQueue(), $requeueMessage);
7580
}
7681

7782
/**

0 commit comments

Comments
 (0)