Completed
Push — master ( 1cf32d...c1056f )
by Matthew
02:25
created

Worker::getWorker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Mpclarkson\ResqueBundle;
4
5
class Worker
6
{
7
    /**
8
     * @var \Resque_Worker
9
     */
10
    protected $worker;
11
12
    public function __construct(\Resque_Worker $worker)
13
    {
14
        $this->worker = $worker;
15
    }
16
17
    public function getId()
18
    {
19
        return (string) $this->worker;
20
    }
21
22
    public function stop()
23
    {
24
        $parts = \explode(':', $this->getId());
25
26
        \posix_kill($parts[1], 3);
27
    }
28
29
    public function getQueues()
30
    {
31
        return \array_map(function($queue) {
32
            return new Queue($queue);
33
        }, $this->worker->queues());
34
    }
35
36
    public function getProcessedCount()
37
    {
38
        return $this->worker->getStat('processed');
39
    }
40
41
    public function getFailedCount()
42
    {
43
        return $this->worker->getStat('failed');
44
    }
45
46
    public function getCurrentJobStart()
47
    {
48
        $job = $this->worker->job();
49
50
        if (!$job) {
51
            return null;
52
        }
53
54
        return new \DateTime($job['run_at']);
55
    }
56
57
    public function getCurrentJob()
58
    {
59
        $job = $this->worker->job();
60
61
        if (!$job) {
62
            return null;
63
        }
64
65
        $job = new \Resque_Job($job['queue'], $job['payload']);
66
67
        return $job->getInstance();
68
    }
69
70
    public function getWorker()
71
    {
72
        return $this->worker;
73
    }
74
}
75