Completed
Push — master ( 410c5e...621de0 )
by Emil
07:36
created

QueueMonitor::setTaskManager()   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
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Glooby\TaskBundle\Queue;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Glooby\TaskBundle\Manager\TaskManager;
7
8
/**
9
 * @author Emil Kilhage
10
 */
11
class QueueMonitor
12
{
13
    /**
14
     * @var ManagerRegistry
15
     */
16
    protected $doctrine;
17
18
    /**
19
     * @param ManagerRegistry $doctrine
20
     */
21
    public function setDoctrine($doctrine)
22
    {
23
        $this->doctrine = $doctrine;
24
    }
25
26
    /**
27
     * @var TaskManager
28
     */
29
    private $taskManager;
30
31
    /**
32
     * @param TaskManager $taskManager
33
     */
34
    public function setTaskManager(TaskManager $taskManager)
35
    {
36
        $this->taskManager = $taskManager;
37
    }
38
39
    /**
40
     *
41
     */
42
    public function monitor()
43
    {
44
        $taskRepo = $this->doctrine->getManager()
45
            ->getRepository('GloobyTaskBundle:QueuedTask');
46
47
        foreach ($taskRepo->findRunning() as $task) {
48
            if (false === posix_getpgid($task->getPId())) {
49
                $this->taskManager->failure($task, 'crashed');
50
            }
51
        }
52
53
        $this->doctrine->getManager()->flush();
54
    }
55
}
56