|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tarantool\Queue; |
| 4 | + |
| 5 | +class Queue |
| 6 | +{ |
| 7 | + private $client; |
| 8 | + private $prefix; |
| 9 | + |
| 10 | + public function __construct(\Tarantool $client, $tubeName) |
| 11 | + { |
| 12 | + $this->client = $client; |
| 13 | + $this->prefix = "queue.tube.$tubeName:"; |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | + * @param mixed $data |
| 18 | + * @param array|null $options |
| 19 | + * |
| 20 | + * @return Task |
| 21 | + */ |
| 22 | + public function put($data, array $options = null) |
| 23 | + { |
| 24 | + $result = $this->client->call($this->prefix.'put', [$data, (array) $options]); |
| 25 | + |
| 26 | + return Task::createFromTuple($result[0]); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @param int|null $timeout |
| 31 | + * |
| 32 | + * @return Task|null |
| 33 | + */ |
| 34 | + public function take($timeout = null) |
| 35 | + { |
| 36 | + $options = null === $timeout ? [] : [(float) $timeout]; |
| 37 | + $result = $this->client->call($this->prefix.'take', $options); |
| 38 | + |
| 39 | + return empty($result[0]) ? null : Task::createFromTuple($result[0]); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @param int $taskId |
| 44 | + * |
| 45 | + * @return Task |
| 46 | + */ |
| 47 | + public function ack($taskId) |
| 48 | + { |
| 49 | + $result = $this->client->call($this->prefix.'ack', [$taskId]); |
| 50 | + |
| 51 | + return Task::createFromTuple($result[0]); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @param int $taskId |
| 56 | + * @param array|null $options |
| 57 | + * |
| 58 | + * @return Task |
| 59 | + */ |
| 60 | + public function release($taskId, array $options = null) |
| 61 | + { |
| 62 | + $result = $this->client->call($this->prefix.'release', [$taskId, (array) $options]); |
| 63 | + |
| 64 | + return Task::createFromTuple($result[0]); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @param int $taskId |
| 69 | + * |
| 70 | + * @return Task |
| 71 | + */ |
| 72 | + public function peek($taskId) |
| 73 | + { |
| 74 | + $result = $this->client->call($this->prefix.'peek', [$taskId]); |
| 75 | + |
| 76 | + return Task::createFromTuple($result[0]); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @param int $taskId |
| 81 | + * |
| 82 | + * @return Task |
| 83 | + */ |
| 84 | + public function bury($taskId) |
| 85 | + { |
| 86 | + $result = $this->client->call($this->prefix.'bury', [$taskId]); |
| 87 | + |
| 88 | + return Task::createFromTuple($result[0]); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @param int $count |
| 93 | + * |
| 94 | + * @return int |
| 95 | + */ |
| 96 | + public function kick($count) |
| 97 | + { |
| 98 | + $result = $this->client->call($this->prefix.'kick', [$count]); |
| 99 | + |
| 100 | + return $result[0][0]; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @param int $taskId |
| 105 | + * |
| 106 | + * @return Task |
| 107 | + */ |
| 108 | + public function delete($taskId) |
| 109 | + { |
| 110 | + $result = $this->client->call($this->prefix.'delete', [$taskId]); |
| 111 | + |
| 112 | + return Task::createFromTuple($result[0]); |
| 113 | + } |
| 114 | +} |
0 commit comments