Repository navigation
Expand file tree
/
Copy pathAbstractQueue.php
More file actions
107 lines (85 loc) · 2.39 KB
/
Copy pathAbstractQueue.php
File metadata and controls
107 lines (85 loc) · 2.39 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* This file is part of the tarantool/queue package.
*
* (c) Eugene Leonovich <gen.work@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Tarantool\Queue;
use Tarantool\Client\Client;
abstract class AbstractQueue
{
public function __construct(
private readonly Client $client,
private readonly string $name,
) {
}
public function getClient() : Client
{
return $this->client;
}
public function getName() : string
{
return $this->name;
}
public function take(?float $timeout = null) : ?Task
{
$result = $this->call('take', $timeout);
return empty($result[0]) ? null : Task::fromTuple($result[0]);
}
public function touch(int $taskId, float $increment) : ?Task
{
$result = $this->call('touch', $taskId, $increment);
return empty($result[0]) ? null : Task::fromTuple($result[0]);
}
public function ack(int $taskId) : Task
{
return Task::fromTuple($this->call('ack', $taskId)[0]);
}
public function peek(int $taskId) : Task
{
return Task::fromTuple($this->call('peek', $taskId)[0]);
}
public function bury(int $taskId) : Task
{
return Task::fromTuple($this->call('bury', $taskId)[0]);
}
public function kick(int $count) : int
{
return $this->call('kick', $count)[0];
}
public function delete(int $taskId) : Task
{
return Task::fromTuple($this->call('delete', $taskId)[0]);
}
public function truncate() : void
{
$this->call('truncate');
}
/**
* @throws \InvalidArgumentException
*
* @return array|int
*/
public function stats(?string $path = null)
{
[$stats] = $this->client->call('queue.stats', $this->name);
if (null === $path) {
return $stats;
}
foreach (explode('.', $path) as $key) {
if (!isset($stats[$key])) {
throw new \InvalidArgumentException(\sprintf('Invalid path "%s"', $path));
}
$stats = $stats[$key];
}
return $stats;
}
public function call(string $methodName, ...$args) : array
{
return $this->client->call("queue.tube.$this->name:$methodName", ...$args);
}
}