forked from michelsalib/BCCResqueBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worker.php
69 lines (53 loc) · 1.21 KB
/
Worker.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
<?php
namespace BCC\ResqueBundle;
class Worker
{
/**
* @var \Resque_Worker
*/
protected $worker;
public function __construct(\Resque_Worker $worker)
{
$this->worker = $worker;
}
public function getId()
{
return (string) $this->worker;
}
public function stop()
{
$parts = \explode(':', $this->getId());
\posix_kill($parts[1], 3);
}
public function getQueues()
{
return \array_map(function ($queue) {
return new Queue($queue);
}, $this->worker->queues());
}
public function getProcessedCount()
{
return $this->worker->getStat('processed');
}
public function getFailedCount()
{
return $this->worker->getStat('failed');
}
public function getCurrentJobStart()
{
$job = $this->worker->job();
if (!$job) {
return null;
}
return new \DateTime($job['run_at']);
}
public function getCurrentJob()
{
$job = $this->worker->job();
if (!$job) {
return null;
}
$job = new \Resque_Job($job['queue'], $job['payload']);
return $job->getInstance();
}
}