Passed
Pull Request — master (#62)
by
unknown
07:41
created

AbstractJobManager::getJobTimingManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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