-
Notifications
You must be signed in to change notification settings - Fork 2
/
GearmanProducer.php
84 lines (67 loc) · 2.06 KB
/
GearmanProducer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace Enqueue\Gearman;
use Interop\Queue\Destination;
use Interop\Queue\Exception\InvalidDestinationException;
use Interop\Queue\Exception\InvalidMessageException;
use Interop\Queue\Exception\PriorityNotSupportedException;
use Interop\Queue\Message;
use Interop\Queue\Producer;
class GearmanProducer implements Producer
{
/**
* @var \GearmanClient
*/
private $client;
public function __construct(\GearmanClient $client)
{
$this->client = $client;
}
/**
* @param GearmanDestination $destination
* @param GearmanMessage $message
*/
public function send(Destination $destination, Message $message): void
{
InvalidDestinationException::assertDestinationInstanceOf($destination, GearmanDestination::class);
InvalidMessageException::assertMessageInstanceOf($message, GearmanMessage::class);
$this->client->doBackground($destination->getName(), json_encode($message));
$code = $this->client->returnCode();
if (\GEARMAN_SUCCESS !== $code) {
throw new \GearmanException(sprintf('The return code is not %s (GEARMAN_SUCCESS) but %s', \GEARMAN_SUCCESS, $code));
}
}
public function setDeliveryDelay(int $deliveryDelay = null): Producer
{
if (null === $deliveryDelay) {
return $this;
}
throw new \LogicException('Not implemented');
}
public function getDeliveryDelay(): ?int
{
return null;
}
public function setPriority(int $priority = null): Producer
{
if (null === $priority) {
return $this;
}
throw PriorityNotSupportedException::providerDoestNotSupportIt();
}
public function getPriority(): ?int
{
return null;
}
public function setTimeToLive(int $timeToLive = null): Producer
{
if (null === $timeToLive) {
return $this;
}
throw new \LogicException('Not implemented');
}
public function getTimeToLive(): ?int
{
return null;
}
}