Completed
Push — master ( c1d220...5e1e72 )
by Phil
07:50 queued 04:46
created

Queue::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace ResqueBundle\Resque;
4
5
/**
6
 * Class Queue
7
 * @package ResqueBundle\Resque
8
 */
9
class Queue
10
{
11
    /**
12
     * @var string The queue name
13
     */
14
    private $name;
15
16
    public function __construct($name)
17
    {
18
        $this->name = $name;
19
    }
20
21
    /**
22
     * @return int
23
     */
24
    public function getSize()
25
    {
26
        return \Resque::size($this->name);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return $this->name;
35
    }
36
37
    /**
38
     * @param int $start
39
     * @param int $stop
40
     * @return array
41
     */
42
    public function getJobs($start = 0, $stop = -1)
43
    {
44
        $jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);
45
46
        $result = [];
47
        foreach ($jobs as $job) {
48
            $job = new \Resque_Job($this->name, \json_decode($job, TRUE));
49
            $result[] = $job->getInstance();
50
        }
51
52
        return $result;
53
    }
54
55
    public function remove()
56
    {
57
        \Resque::redis()->srem('queues', $this->name);
58
    }
59
60
    /**
61
     * @return int
62
     */
63
    public function clear()
64
    {
65
        $length = \Resque::redis()->llen('queue:' . $this->name);
66
        \Resque::redis()->del('queue:' . $this->name);
67
        return $length;
68
    }
69
}
70