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