-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPool.php
More file actions
66 lines (56 loc) · 1.66 KB
/
Pool.php
File metadata and controls
66 lines (56 loc) · 1.66 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
<?php
namespace Utopia\Queue\Broker;
use Utopia\Queue\Consumer;
use Utopia\Queue\Publisher;
use Utopia\Queue\Queue;
use Utopia\Pools\Pool as UtopiaPool;
readonly class Pool implements Publisher, Consumer
{
public function __construct(
private ?UtopiaPool $publisher = null,
private ?UtopiaPool $consumer = null,
) {
}
public function enqueue(Queue $queue, array $payload): bool
{
return $this->delegatePublish(__FUNCTION__, \func_get_args());
}
public function retry(Queue $queue, ?int $limit = null): void
{
$this->delegatePublish(__FUNCTION__, \func_get_args());
}
public function getQueueSize(Queue $queue, bool $failedJobs = false): int
{
return $this->delegatePublish(__FUNCTION__, \func_get_args());
}
public function consume(
Queue $queue,
callable $messageCallback,
callable $successCallback,
callable $errorCallback,
): void {
$this->delegateConsumer(__FUNCTION__, \func_get_args());
}
public function close(): void
{
// TODO: Implement closing all connections in the pool
}
protected function delegatePublish(string $method, array $args): mixed
{
return $this->publisher?->use(function (Publisher $adapter) use (
$method,
$args,
) {
return $adapter->$method(...$args);
});
}
protected function delegateConsumer(string $method, array $args): mixed
{
return $this->consumer?->use(function (Consumer $adapter) use (
$method,
$args,
) {
return $adapter->$method(...$args);
});
}
}