Completed
Pull Request — master (#40)
by Matthew
17:20
created

AbstractJobManager::pruneStalledJobs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Dtc\QueueBundle\Manager;
4
5
use Dtc\QueueBundle\Exception\UnsupportedException;
6
use Dtc\QueueBundle\Model\BaseJob;
7
use Dtc\QueueBundle\Model\Job;
8
9
abstract class AbstractJobManager implements JobManagerInterface
10
{
11
    protected $jobTiminigManager;
12
    protected $jobClass;
13
    protected $runManager;
14 43
15
    public function __construct(RunManager $runManager, JobTimingManager $jobTimingManager, $jobClass)
16 43
    {
17 43
        $this->runManager = $runManager;
18 43
        $this->jobTiminigManager = $jobTimingManager;
19 43
        $this->jobClass = $jobClass;
20
    }
21
22
    /**
23
     * @return array
24 68
     */
25
    public static function getAllStatuses()
26 68
    {
27
        return [
28
                BaseJob::STATUS_NEW => 0,
29
                BaseJob::STATUS_RUNNING => 0,
30
                BaseJob::STATUS_SUCCESS => 0,
31
                BaseJob::STATUS_FAILURE => 0,
32 79
                BaseJob::STATUS_EXCEPTION => 0,
33
                \Dtc\QueueBundle\Model\Job::STATUS_EXPIRED => 0, ];
34 79
    }
35
36
    public function getStatus()
37
    {
38
        $count = $this->getWaitingJobCount();
39
        $allStatuses = static::getAllStatuses();
40 4
        foreach (array_keys($allStatuses) as $status) {
41
            $allStatuses[$status] = 'unknown';
42 4
        }
43
        $allStatuses[BaseJob::STATUS_NEW] = $count;
44
45
        return ['all' => $allStatuses];
46
    }
47
48
    /**
49
     * @return string
50
     */
51 5
    public function getJobClass()
52
    {
53 5
        return $this->jobClass;
54
    }
55
56 5
    /**
57
     * @return JobTimingManager
58 5
     */
59
    public function getJobTimingManager()
60
    {
61 5
        return $this->jobTiminigManager;
62
    }
63 5
64
    /**
65
     * @return RunManager
66 5
     */
67
    public function getRunManager()
68 5
    {
69
        return $this->runManager;
70
    }
71
72
    abstract public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null);
73
74
    abstract public function save(Job $job);
75
76 4
    abstract public function saveHistory(Job $job);
77
78 4
    public function resetExceptionJobs($workerName = null, $methodName = null)
79
    {
80
        throw new UnsupportedException('Unsupported');
81 4
    }
82
83 4
    public function pruneExceptionJobs($workerName = null, $methodName = null)
84
    {
85
        throw new UnsupportedException('Unsupported');
86 1
    }
87
88 1
    public function getWaitingJobCount($workerName = null, $methodName = null)
89
    {
90
        throw new UnsupportedException('Unsupported');
91 5
    }
92
93 5
    public function deleteJob(Job $job)
94
    {
95
        throw new UnsupportedException('Unsupported');
96 5
    }
97
98 5
    public function pruneExpiredJobs($workerName = null, $methodName = null)
99
    {
100
        throw new UnsupportedException('Unsupported');
101
    }
102
103
    public function pruneArchivedJobs(\DateTime $olderThan)
104
    {
105
        throw new UnsupportedException('Unsupported');
106
    }
107
}
108