-
Notifications
You must be signed in to change notification settings - Fork 29
/
Queue.php
76 lines (65 loc) · 1.48 KB
/
Queue.php
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
<?php
/*
* @copyright Copyright (C) 2019, 2022, 2021, 2022 Blue Flame Digital Solutions Limited / Phil Taylor. All rights reserved.
* @author Phil Taylor <[email protected]> and others, see README.md
* @see https://github.com/resquebundle/resque
* @license MIT
*/
namespace ResqueBundle\Resque;
/**
* Class Queue.
*/
class Queue
{
/**
* @var string The queue name
*/
private $name;
public function __construct($name)
{
$this->name = $name;
}
/**
* @return int
*/
public function getSize()
{
return \Resque::size($this->name);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param int $start
* @param int $stop
*
* @return array
*/
public function getJobs($start = 0, $stop = -1)
{
$jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);
$result = [];
foreach ($jobs as $job) {
$job = new \Resque_Job($this->name, json_decode($job, true));
$result[] = $job->getInstance();
}
return $result;
}
public function remove()
{
\Resque::redis()->srem('queues', $this->name);
}
/**
* @return int
*/
public function clear()
{
$length = \Resque::redis()->llen('queue:' . $this->name);
\Resque::redis()->del('queue:' . $this->name);
return $length;
}
}