1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Resque; |
6
|
|
|
|
7
|
|
|
use Psr\Container\ContainerInterface; |
8
|
|
|
use Resque\Dispatchers\Noop; |
9
|
|
|
use Resque\Exceptions\PayloadCorrupt; |
10
|
|
|
use Resque\Interfaces\Dispatcher; |
11
|
|
|
use Resque\Tasks\AfterUserJobPerform; |
12
|
|
|
use Resque\Tasks\BeforeUserJobPerform; |
13
|
|
|
use Resque\Tasks\FailedUserJobPerform; |
14
|
|
|
|
15
|
|
|
class Job |
16
|
|
|
{ |
17
|
|
|
private $queueName; |
18
|
|
|
private $payload; |
19
|
|
|
private $serviceLocator; |
20
|
|
|
private $dispatcher; |
21
|
|
|
private $failed = false; |
22
|
|
|
|
23
|
7 |
|
public function __construct(string $queueName, array $payload, ContainerInterface $serviceLocator) |
24
|
|
|
{ |
25
|
7 |
|
$this->queueName = $queueName; |
26
|
7 |
|
$this->payload = $payload; |
27
|
7 |
|
$this->serviceLocator = $serviceLocator; |
28
|
7 |
|
$this->dispatcher = new Noop(); |
29
|
7 |
|
} |
30
|
|
|
|
31
|
7 |
|
public function setDispatcher(Dispatcher $dispatcher): void |
32
|
|
|
{ |
33
|
7 |
|
$this->dispatcher = $dispatcher; |
34
|
7 |
|
} |
35
|
|
|
|
36
|
3 |
|
public function getPayloadClassName(): string |
37
|
|
|
{ |
38
|
3 |
|
if (empty($this->payload['class'])) { |
39
|
|
|
throw new PayloadCorrupt(); |
40
|
|
|
} |
41
|
3 |
|
return $this->payload['class']; |
42
|
|
|
} |
43
|
|
|
|
44
|
3 |
|
public function getPayloadArguments(): array |
45
|
|
|
{ |
46
|
3 |
|
if (empty($this->payload['args'])) { |
47
|
|
|
throw new PayloadCorrupt(); |
48
|
|
|
} |
49
|
3 |
|
return $this->payload['args']; |
50
|
|
|
} |
51
|
|
|
|
52
|
7 |
|
public function getQueueName(): string |
53
|
|
|
{ |
54
|
7 |
|
return $this->queueName; |
55
|
|
|
} |
56
|
|
|
|
57
|
7 |
|
public function getPayload(): array |
58
|
|
|
{ |
59
|
7 |
|
return $this->payload; |
60
|
|
|
} |
61
|
|
|
|
62
|
6 |
|
public function hasFailed(): bool |
63
|
|
|
{ |
64
|
6 |
|
return $this->failed; |
65
|
|
|
} |
66
|
|
|
|
67
|
3 |
|
public function perform(): void |
68
|
|
|
{ |
69
|
3 |
|
$this->dispatcher->dispatch(BeforeUserJobPerform::class, $this->payload); |
70
|
|
|
try { |
71
|
3 |
|
$userJob = $this->serviceLocator->get($this->getPayloadClassName()); |
72
|
3 |
|
$userJob->perform($this->getPayloadArguments()); |
73
|
1 |
|
$this->dispatcher->dispatch(AfterUserJobPerform::class, $this->payload); |
74
|
2 |
|
} catch (\Exception $e) { |
75
|
1 |
|
$this->handleFailedJob(); |
76
|
1 |
|
} catch (\Error $e) { |
77
|
1 |
|
$this->handleBrokenJob(); |
78
|
|
|
} |
79
|
3 |
|
} |
80
|
|
|
|
81
|
1 |
|
private function handleFailedJob() |
82
|
|
|
{ |
83
|
1 |
|
$this->failed = true; |
84
|
1 |
|
$this->dispatcher->dispatch(FailedUserJobPerform::class, $this->payload); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
1 |
|
private function handleBrokenJob() |
88
|
|
|
{ |
89
|
1 |
|
$this->failed = true; |
90
|
1 |
|
$this->dispatcher->dispatch(BrokenUserJobPerform::class, $this->payload); |
|
|
|
|
91
|
1 |
|
} |
92
|
|
|
} |
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths