Completed
Push — master ( c5ed18...ed0fce )
by Nathan
07:36
created

JobWorker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A jobqueueExecute() 0 13 3
1
<?php
2
3
namespace Symbiote\QueuedJobs\Workers;
4
5
use SilverStripe\ORM\DataList;
6
7
/**
8
 * @author [email protected]
9
 * @license BSD License http://silverstripe.org/bsd-license/
10
 */
11
12
// GearmanHandler is an extension that could be not available.
13
/**
14
 * @todo Test and implement against it for SilverStripe 4.x compatibility
15
 */
16
if (interface_exists('GearmanHandler')) {
17
    class JobWorker implements \GearmanHandler
18
    {
19
        /**
20
         * @var QueuedJobService
21
         */
22
        public $queuedJobService;
23
24
        /**
25
         * @return string
26
         */
27
        public function getName()
28
        {
29
            return 'jobqueueExecute';
30
        }
31
32
        /**
33
         * @param int $jobId
34
         * @return void
35
         */
36
        public function jobqueueExecute($jobId)
37
        {
38
            $this->queuedJobService->checkJobHealth();
39
            $job = DataList::create('Symbiote\\QueuedJobs\\DataObjects\\QueuedJobDescriptor')->byID($jobId);
40
            if ($job) {
41
                // check that we're not trying to execute something tooo soon
42
                if (strtotime($job->StartAfter) > time()) {
43
                    return;
44
                }
45
46
                $this->queuedJobService->runJob($jobId);
47
            }
48
        }
49
    }
50
}
51