|
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\Job\ExceptionJobResult; |
|
16
|
|
|
use Core\Queue\Job\JobResult; |
|
17
|
|
|
use Core\Queue\Job\ResultProviderInterface; |
|
18
|
|
|
use Core\Queue\LoggerAwareJobTrait; |
|
19
|
|
|
use Core\Queue\MongoQueue; |
|
20
|
|
|
use SlmQueue\Job\JobInterface; |
|
21
|
|
|
use SlmQueue\Queue\QueueAwareInterface; |
|
22
|
|
|
use SlmQueue\Queue\QueueInterface; |
|
23
|
|
|
use SlmQueue\Worker\AbstractWorker; |
|
24
|
|
|
use SlmQueue\Worker\Event\ProcessJobEvent; |
|
25
|
|
|
use Zend\Log\LoggerAwareInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Queue worker for the mongo queue. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class MongoWorker extends AbstractWorker implements LoggerAwareInterface |
|
33
|
|
|
{ |
|
34
|
|
|
use LoggerAwareJobTrait; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Process job handler. |
|
38
|
|
|
* |
|
39
|
|
|
* @param JobInterface $job |
|
40
|
|
|
* @param QueueInterface $queue |
|
41
|
|
|
* |
|
42
|
|
|
* @return int|void |
|
43
|
|
|
*/ |
|
44
|
4 |
|
public function processJob(JobInterface $job, QueueInterface $queue) |
|
45
|
|
|
{ |
|
46
|
4 |
|
if (!$queue instanceof MongoQueue) { |
|
47
|
1 |
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
3 |
|
if ($job instanceOf QueueAwareInterface) { |
|
51
|
|
|
$job->setQueue($queue); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
try { |
|
55
|
3 |
|
return $job->execute(); |
|
56
|
2 |
|
} catch (\Exception $exception) { |
|
57
|
2 |
|
$this->getLogger()->err('Job execution thrown exception: ' . get_class($exception)); |
|
58
|
|
|
|
|
59
|
2 |
|
if ($job instanceOf ResultProviderInterface) { |
|
60
|
|
|
$job->setResult(JobResult::failure($exception->getMessage(), [$exception->getTraceAsString()])); |
|
61
|
|
|
} else { |
|
62
|
2 |
|
$this->getLogger()->err($exception->getMessage(), [$exception->getTraceAsString()]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
return ProcessJobEvent::JOB_STATUS_FAILURE; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|