AbstractJobManager   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Test Coverage

Coverage 94.59%

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 100
ccs 35
cts 37
cp 0.9459
rs 10
wmc 13

12 Methods

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