-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueManager.php
More file actions
83 lines (73 loc) · 2.14 KB
/
QueueManager.php
File metadata and controls
83 lines (73 loc) · 2.14 KB
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
<?php
namespace Altair\Queue;
use Altair\Middleware\Contracts\MiddlewareManagerInterface;
use Altair\Middleware\Contracts\PayloadInterface;
use Altair\Queue\Contracts\JobInterface;
use Altair\Queue\Contracts\QueueAdapterInterface;
use Altair\Queue\Contracts\QueueManagerInterface;
class QueueManager implements QueueManagerInterface
{
protected $adapter;
protected $pushProcessor;
protected $popProcessor;
/**
* Manager constructor.
*
* @param QueueAdapterInterface $adapter
* @param MiddlewareManagerInterface $pushProcessor
* @param MiddlewareManagerInterface $popProcessor
*/
public function __construct(
QueueAdapterInterface $adapter,
MiddlewareManagerInterface $pushProcessor = null,
MiddlewareManagerInterface $popProcessor = null
) {
$this->adapter = $adapter;
$this->pushProcessor = $pushProcessor;
$this->popProcessor = $popProcessor;
}
/**
* @inheritdoc
*/
public function getAdapter(): QueueAdapterInterface
{
return $this->adapter;
}
/**
* @inheritdoc
*/
public function push(PayloadInterface $payload): bool
{
if (null !== $this->pushProcessor) {
$payload = call_user_func([$this->pushProcessor, '__invoke'], $payload);
}
return $this->adapter->push($payload);
}
/**
* @inheritdoc
*/
public function pop(string $queue = null): ?PayloadInterface
{
$payload = $this->adapter->pop($queue);
return null !== $this->popProcessor
? call_user_func([$this->popProcessor, '__invoke'], $payload)
: $payload;
}
/**
* @inheritdoc
*/
public function ack(PayloadInterface $payload)
{
if ($payload->getAttribute(JobInterface::ATTRIBUTE_COMPLETED) !== true && null !== $this->pushProcessor) {
$payload = call_user_func([$this->pushProcessor, '__invoke'], $payload);
}
$this->adapter->ack($payload);
}
/**
* @inheritdoc
*/
public function isEmpty(string $queue = null): bool
{
return $this->adapter->isEmpty($queue);
}
}