Skip to content

Commit 85c81b1

Browse files
committed
[gearman] Add requeue support.
1 parent 4bc8ecf commit 85c81b1

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎pkg/gearman/GearmanConsumer.php‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ class GearmanConsumer implements PsrConsumer
1818
private $destination;
1919

2020
/**
21-
* @param \GearmanWorker $worker
21+
* @var GearmanContext
22+
*/
23+
private $context;
24+
25+
/**
26+
* @param GearmanContext $context
2227
* @param GearmanDestination $destination
28+
*
29+
* @internal param \GearmanWorker $worker
2330
*/
24-
public function __construct(\GearmanWorker $worker, GearmanDestination $destination)
31+
public function __construct(GearmanContext $context, GearmanDestination $destination)
2532
{
26-
$this->worker = $worker;
33+
$this->context = $context;
2734
$this->destination = $destination;
35+
36+
$this->worker = $context->createWorker();
2837
}
2938

3039
/**
@@ -85,6 +94,9 @@ public function acknowledge(PsrMessage $message)
8594
*/
8695
public function reject(PsrMessage $message, $requeue = false)
8796
{
97+
if ($requeue) {
98+
$this->context->createProducer()->send($this->destination, $message);
99+
}
88100
}
89101

90102
/**

‎pkg/gearman/GearmanContext.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function createConsumer(PsrDestination $destination)
8888
{
8989
InvalidDestinationException::assertDestinationInstanceOf($destination, GearmanDestination::class);
9090

91-
$this->consumers[] = $consumer = new GearmanConsumer($this->createWorker(), $destination);
91+
$this->consumers[] = $consumer = new GearmanConsumer($this, $destination);
9292

9393
return $consumer;
9494
}

0 commit comments

Comments
 (0)