Completed
Pull Request — develop (#533)
by Mathias
07:53
created

MongoWorker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A processJob() 0 21 4
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2019 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Queue\Worker;
12
13
use Core\Queue\Exception\FatalJobException;
14
use Core\Queue\Exception\RecoverableJobException;
15
use Core\Queue\MongoQueue;
16
use SlmQueue\Job\JobInterface;
17
use SlmQueue\Queue\QueueInterface;
18
use SlmQueue\Worker\AbstractWorker;
19
use SlmQueue\Worker\Event\ProcessJobEvent;
20
21
/**
22
 * Queue worker for the mongo queue.
23
 *
24
 * @author Mathias Gelhausen <[email protected]>
25
 */
26
class MongoWorker extends AbstractWorker
27
{
28
    /**
29
     * Process job handler.
30
     *
31
     * @param JobInterface   $job
32
     * @param QueueInterface $queue
33
     *
34
     * @return int|void
35
     */
36 4
    public function processJob(JobInterface $job, QueueInterface $queue)
37
    {
38 4
        if (!$queue instanceof MongoQueue) {
39 1
            return;
40
        }
41
42
        try {
43 3
            $job->execute();
44 1
            $queue->delete($job);
45
46 1
            return ProcessJobEvent::JOB_STATUS_SUCCESS;
47
48 2
        } catch (RecoverableJobException $exception) {
49 1
            $queue->retry($job, $exception->getOptions());
50
51 1
            return ProcessJobEvent::JOB_STATUS_FAILURE_RECOVERABLE;
52
53 1
        } catch (FatalJobException $exception) {
54 1
            $queue->fail($job, $exception->getOptions());
55
56 1
            return ProcessJobEvent::JOB_STATUS_FAILURE;
57
        }
58
    }
59
}
60