1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Laravel Queue for AWS Batch. |
5
|
|
|
* |
6
|
|
|
* @author Luke Waite <[email protected]> |
7
|
|
|
* @copyright 2017 Luke Waite |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* |
10
|
|
|
* @link https://github.com/lukewaite/laravel-queue-aws-batch |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace LukeWaite\LaravelQueueAwsBatch\Console; |
14
|
|
|
|
15
|
|
|
use Illuminate\Console\Command; |
16
|
|
|
use Illuminate\Foundation\Exceptions\Handler; |
17
|
|
|
use Illuminate\Queue\Console\WorkCommand; |
18
|
|
|
use Illuminate\Queue\QueueManager; |
19
|
|
|
use Illuminate\Queue\Worker; |
20
|
|
|
use Illuminate\Queue\WorkerOptions; |
21
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Exceptions\JobNotFoundException; |
22
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException; |
23
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue; |
24
|
|
|
use Symfony\Component\Debug\Exception\FatalThrowableError; |
|
|
|
|
25
|
|
|
|
26
|
|
|
class QueueWorkBatchCommand extends WorkCommand |
27
|
|
|
{ |
28
|
|
|
protected $name = 'queue:work-batch'; |
29
|
|
|
|
30
|
|
|
protected $description = 'Run a Job for the AWS Batch queue'; |
31
|
|
|
|
32
|
|
|
protected $signature = 'queue:work-batch |
33
|
|
|
{job_id : The job id in the database} |
34
|
|
|
{connection? : The name of the queue connection to work} |
35
|
|
|
{--memory=128 : The memory limit in megabytes} |
36
|
|
|
{--timeout=60 : The number of seconds a child process can run} |
37
|
|
|
{--tries=0 : Number of times to attempt a job before logging it failed}'; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
protected $manager; |
41
|
|
|
protected $exceptions; |
42
|
|
|
|
43
|
|
|
public function __construct(QueueManager $manager, Worker $worker, Handler $exceptions) |
44
|
|
|
{ |
45
|
|
|
parent::__construct($worker); |
|
|
|
|
46
|
|
|
$this->manager = $manager; |
47
|
|
|
$this->exceptions = $exceptions; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function fire() |
51
|
|
|
{ |
52
|
|
|
$this->listenForEvents(); |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
$this->runJob(); |
56
|
|
|
} catch (\Exception $e) { |
57
|
|
|
$this->exceptions->report($e); |
58
|
|
|
throw $e; |
59
|
|
|
} catch (\Throwable $e) { |
60
|
|
|
$this->exceptions->report(new FatalThrowableError($e)); |
61
|
|
|
throw $e; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// TOOD: Refactor out the logic here into an extension of the Worker class |
66
|
|
|
protected function runJob() |
67
|
|
|
{ |
68
|
|
|
$connectionName = $this->argument('connection'); |
69
|
|
|
$jobId = $this->argument('job_id'); |
70
|
|
|
|
71
|
|
|
/** @var BatchQueue $connection */ |
72
|
|
|
$connection = $this->manager->connection($connectionName); |
|
|
|
|
73
|
|
|
|
74
|
|
|
if (!$connection instanceof BatchQueue) { |
|
|
|
|
75
|
|
|
throw new UnsupportedException('queue:work-batch can only be run on batch queues'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$job = $connection->getJobById($jobId, $connectionName); |
|
|
|
|
79
|
|
|
|
80
|
|
|
// If we're able to pull a job off of the stack, we will process it and |
81
|
|
|
// then immediately return back out. |
82
|
|
|
if (!is_null($job)) { |
83
|
|
|
return $this->worker->process( |
|
|
|
|
84
|
|
|
$this->manager->getName($connectionName), |
|
|
|
|
85
|
|
|
$job, |
86
|
|
|
$this->gatherWorkerOptions() |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// If we hit this point, we haven't processed our job |
91
|
|
|
throw new JobNotFoundException('No job was returned'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Gather all of the queue worker options as a single object. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Queue\WorkerOptions |
98
|
|
|
*/ |
99
|
|
|
protected function gatherWorkerOptions() |
100
|
|
|
{ |
101
|
|
|
return new WorkerOptions( |
102
|
|
|
0, |
103
|
|
|
$this->option('memory'), |
104
|
|
|
$this->option('timeout'), |
105
|
|
|
0, |
106
|
|
|
$this->option('tries'), |
107
|
|
|
false |
|
|
|
|
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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