16
16
use Illuminate \Queue \Console \WorkCommand ;
17
17
use Illuminate \Queue \QueueManager ;
18
18
use Illuminate \Queue \Worker ;
19
+ use Illuminate \Queue \WorkerOptions ;
19
20
use LukeWaite \LaravelQueueAwsBatch \Exceptions \JobNotFoundException ;
20
21
use LukeWaite \LaravelQueueAwsBatch \Exceptions \UnsupportedException ;
21
22
use LukeWaite \LaravelQueueAwsBatch \Queues \BatchQueue ;
@@ -27,7 +28,13 @@ class QueueWorkBatchCommand extends WorkCommand
27
28
28
29
protected $ description = 'Run a Job for the AWS Batch queue ' ;
29
30
30
- protected $ signature = 'queue:work-batch {connection} {job_id} {--tries=} ' ;
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
+
31
38
32
39
protected $ manager ;
33
40
protected $ exceptions ;
@@ -41,6 +48,8 @@ public function __construct(QueueManager $manager, Worker $worker, Handler $exce
41
48
42
49
public function fire ()
43
50
{
51
+ $ this ->listenForEvents ();
52
+
44
53
try {
45
54
$ this ->runJob ();
46
55
} catch (\Exception $ e ) {
@@ -70,7 +79,7 @@ protected function runJob()
70
79
// If we're able to pull a job off of the stack, we will process it and
71
80
// then immediately return back out.
72
81
if (!is_null ($ job )) {
73
- $ this ->worker ->process (
82
+ return $ this ->worker ->process (
74
83
$ this ->manager ->getName ($ connectionName ),
75
84
$ job ,
76
85
$ this ->gatherWorkerOptions ()
@@ -80,4 +89,18 @@ protected function runJob()
80
89
// If we hit this point, we haven't processed our job
81
90
throw new JobNotFoundException ('No job was returned ' );
82
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
+ }
83
106
}
0 commit comments