Issues (7)

src/CircularQueue.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Created by solly [31.10.17 15:41]
4
 */
5
6
namespace insolita\cqueue;
7
8
use Carbon\Carbon;
9
use insolita\cqueue\Contracts\DelayingInterface;
10
use insolita\cqueue\Mixins\DelayingTrait;
11
12
class CircularQueue extends SimpleCircularQueue implements DelayingInterface
13
{
14
    use DelayingTrait;
0 ignored issues
show
The trait insolita\cqueue\Mixins\DelayingTrait requires the property $timestamp which is not provided by insolita\cqueue\CircularQueue.
Loading history...
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()
43
    {
44
        $this->resumeExpired();
45
    }
46
}
47