forked from michelsalib/BCCResqueBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResque.php
More file actions
executable file
·60 lines (47 loc) · 1.24 KB
/
Resque.php
File metadata and controls
executable file
·60 lines (47 loc) · 1.24 KB
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
<?php
namespace BCC\ResqueBundle;
class Resque
{
/**
* @var array
*/
private $kernelOptions;
function __construct(array $kernelOptions)
{
$this->kernelOptions = $kernelOptions;
// HACK, prune dead workers, just in case
$worker = new \Resque_Worker('temp');
$worker->pruneDeadWorkers();
}
public function enqueue(Job $job, $trackStatus = false)
{
if ($job instanceof ContainerAwareJob) {
$job->setKernelOptions($this->kernelOptions);
}
$result = \Resque::enqueue($job->queue, \get_class($job), $job->args, $trackStatus);
if ($trackStatus) {
return new \Resque_Job_Status($result);
}
return null;
}
public function getQueues()
{
return \array_map(function ($queue) {
return new Queue($queue);
}, \Resque::queues());
}
public function getWorkers()
{
return \array_map(function ($worker) {
return new Worker($worker);
}, \Resque_Worker::all());
}
public function getWorker($id)
{
$worker = \Resque_Worker::find($id);
if(!$worker) {
return null;
}
return new Worker($worker);
}
}