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\QueueManager; |
17
|
|
|
use Illuminate\Queue\Worker; |
18
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Exceptions\JobNotFoundException; |
19
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException; |
20
|
|
|
use LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue; |
21
|
|
|
use Symfony\Component\Debug\Exception\FatalThrowableError; |
22
|
|
|
|
23
|
|
|
class QueueWorkBatchCommand extends Command |
24
|
|
|
{ |
25
|
|
|
protected $name = 'queue:work-batch'; |
26
|
|
|
|
27
|
|
|
protected $description = 'Run a Job for the AWS Batch queue'; |
28
|
|
|
|
29
|
|
|
protected $signature = 'queue:work-batch {connection} {job_id} {--tries=}'; |
30
|
|
|
|
31
|
|
|
protected $manager; |
32
|
|
|
protected $worker; |
33
|
|
|
protected $exceptions; |
34
|
|
|
|
35
|
|
|
public function __construct(QueueManager $manager, Worker $worker, Handler $exceptions) |
36
|
|
|
{ |
37
|
|
|
$this->worker = $worker; |
38
|
|
|
$this->manager = $manager; |
39
|
|
|
$this->exceptions = $exceptions; |
40
|
|
|
parent::__construct(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function fire() |
44
|
|
|
{ |
45
|
|
|
try { |
46
|
|
|
$this->runJob(); |
47
|
|
|
} catch (\Exception $e) { |
48
|
|
|
$this->exceptions->report($e); |
49
|
|
|
throw $e; |
50
|
|
|
} catch (\Throwable $e) { |
|
|
|
|
51
|
|
|
$this->exceptions->report(new FatalThrowableError($e)); |
52
|
|
|
throw $e; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function runJob() |
57
|
|
|
{ |
58
|
|
|
$maxTries = $this->option('tries'); |
59
|
|
|
$delay = 0; |
60
|
|
|
|
61
|
|
|
$connectionName = $this->argument('connection'); |
62
|
|
|
$jobId = $this->argument('job_id'); |
63
|
|
|
|
64
|
|
|
/** @var BatchQueue $connection */ |
65
|
|
|
$connection = $this->manager->connection($connectionName); |
|
|
|
|
66
|
|
|
|
67
|
|
|
if (!$connection instanceof BatchQueue) { |
68
|
|
|
throw new UnsupportedException('queue:work-batch can only be run on batch queues'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$job = $connection->getJobById($jobId, $connectionName); |
72
|
|
|
|
73
|
|
|
// If we're able to pull a job off of the stack, we will process it and |
74
|
|
|
// then immediately return back out. |
75
|
|
|
if (!is_null($job)) { |
76
|
|
|
return $this->worker->process( |
77
|
|
|
$this->manager->getName($connectionName), |
|
|
|
|
78
|
|
|
$job, |
79
|
|
|
$maxTries, |
|
|
|
|
80
|
|
|
$delay |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// If we hit this point, we haven't processed our job |
85
|
|
|
throw new JobNotFoundException('No job was returned'); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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.