Completed
Pull Request — master (#40)
by Matthew
07:31
created

AbstractJobManager::resetStalledJobs()   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
15 43
    public function __construct(RunManager $runManager, JobTimingManager $jobTimingManager, $jobClass)
16
    {
17 43
        $this->runManager = $runManager;
18 43
        $this->jobTiminigManager = $jobTimingManager;
19 43
        $this->jobClass = $jobClass;
20 43
    }
21
22
    /**
23
     * @return array
24
     */
25 9
    public static function getAllStatuses()
26
    {
27
        return [
28 9
                BaseJob::STATUS_NEW => 0,
29 9
                BaseJob::STATUS_RUNNING => 0,
30 9
                BaseJob::STATUS_SUCCESS => 0,
31 9
                BaseJob::STATUS_FAILURE => 0,
32 9
                BaseJob::STATUS_EXCEPTION => 0,
33 9
                \Dtc\QueueBundle\Model\Job::STATUS_EXPIRED => 0, ];
34
    }
35
36 5
    public function getStatus()
37
    {
38 5
        $count = $this->getWaitingJobCount();
39 5
        $allStatuses = static::getAllStatuses();
40 5
        foreach (array_keys($allStatuses) as $status) {
41 5
            $allStatuses[$status] = 'N/A';
42
        }
43 5
        $allStatuses[BaseJob::STATUS_NEW] = $count;
44
45 5
        return ['all' => $allStatuses];
46
    }
47
48
    /**
49
     * @return string
50
     */
51 68
    public function getJobClass()
52
    {
53 68
        return $this->jobClass;
54
    }
55
56
    /**
57
     * @return JobTimingManager
58
     */
59 80
    public function getJobTimingManager()
60
    {
61 80
        return $this->jobTiminigManager;
62
    }
63
64
    /**
65
     * @return RunManager
66
     */
67 4
    public function getRunManager()
68
    {
69 4
        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
    abstract public function saveHistory(Job $job);
77
78 5
    public function resetExceptionJobs($workerName = null, $methodName = null)
79
    {
80 5
        throw new UnsupportedException('Unsupported');
81
    }
82
83 5
    public function pruneExceptionJobs($workerName = null, $methodName = null)
84
    {
85 5
        throw new UnsupportedException('Unsupported');
86
    }
87
88
    public function getWaitingJobCount($workerName = null, $methodName = null)
89
    {
90
        throw new UnsupportedException('Unsupported');
91
    }
92
93 1
    public function deleteJob(Job $job)
94
    {
95 1
        throw new UnsupportedException('Unsupported');
96
    }
97
98 5
    public function pruneExpiredJobs($workerName = null, $methodName = null)
99
    {
100 5
        throw new UnsupportedException('Unsupported');
101
    }
102
103 5
    public function pruneArchivedJobs(\DateTime $olderThan)
104
    {
105 5
        throw new UnsupportedException('Unsupported');
106
    }
107
}
108