| Total Complexity | 6 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class CircularQueue extends SimpleCircularQueue implements DelayingInterface |
||
| 13 | { |
||
| 14 | use DelayingTrait; |
||
|
|
|||
| 15 | |||
| 16 | public function countTotal():int |
||
| 17 | { |
||
| 18 | return $this->countQueued() + $this->countDelayed(); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function next() |
||
| 22 | { |
||
| 23 | $this->beforePull(); |
||
| 24 | return parent::next(); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function pull(int $ttl = 0) |
||
| 28 | { |
||
| 29 | $this->beforePull(); |
||
| 30 | $item = $this->storage->listPop($this->queueKey()); |
||
| 31 | if (!$item) { |
||
| 32 | return $this->emptyQueueBehavior->resolve($this); |
||
| 33 | } else { |
||
| 34 | if ($ttl > 0) { |
||
| 35 | $resumeTime = Carbon::now()->timestamp + $ttl; |
||
| 36 | $this->storage->zSetPush($this->delayedKey(), $resumeTime, $item); |
||
| 37 | } |
||
| 38 | return $this->converter->toPayload($item); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | protected function beforePull() |
||
| 45 | } |
||
| 46 | } |
||
| 47 |