@@ -30,14 +30,14 @@ class QueueShell extends Shell {
30
30
public $ modelClass = 'Queue.QueuedJobs ' ;
31
31
32
32
/**
33
- * @var array
33
+ * @var array|null
34
34
*/
35
35
protected $ _taskConf ;
36
36
37
37
/**
38
38
* @var bool
39
39
*/
40
- protected $ _exit ;
40
+ protected $ _exit = false ;
41
41
42
42
/**
43
43
* Overwrite shell initialize to dynamically load all Queue Related Tasks.
@@ -74,31 +74,22 @@ public function initialize() {
74
74
}
75
75
76
76
/**
77
- * Output some basic usage Info.
78
- *
79
- * @return void
77
+ * @return string
80
78
*/
81
- public function main () {
82
- $ this ->out ('CakePHP Queue Plugin: ' );
83
- $ this ->hr ();
84
- $ this ->out ('Usage: ' );
85
- $ this ->out (' cake Queue.Queue help ' );
86
- $ this ->out (' -> Display this Help message ' );
87
- $ this ->out (' cake Queue.Queue add <taskname> ' );
88
- $ this ->out (' -> Try to call the cli add() function on a task ' );
89
- $ this ->out (' -> tasks may or may not provide this functionality. ' );
90
- $ this ->out (' cake Queue.Queue runworker ' );
91
- $ this ->out (' -> run a queue worker, which will look for a pending task it can execute. ' );
92
- $ this ->out (' -> the worker will always try to find jobs matching its installed Tasks ' );
93
- $ this ->out (' -> see "Available Tasks" below. ' );
94
- $ this ->out (' cake Queue.Queue stats ' );
95
- $ this ->out (' -> Display some general Statistics. ' );
96
- $ this ->out (' cake Queue.Queue clean ' );
97
- $ this ->out (' -> Manually call cleanup function to delete task data of completed tasks. ' );
98
- $ this ->out ('Notes: ' );
99
- $ this ->out (' <taskname> may either be the complete class name (eg. QueueExample) ' );
100
- $ this ->out (' or the shorthand without the leading "Queue" (eg. Example) ' );
101
- $ this ->_displayAvailableTasks ();
79
+ public function _getDescription () {
80
+ $ tasks = [];
81
+ foreach ($ this ->taskNames as $ loadedTask ) {
82
+ $ tasks [] = "\t" . '* ' . $ this ->_taskName ($ loadedTask );
83
+ }
84
+ $ tasks = implode (PHP_EOL , $ tasks );
85
+
86
+ $ text = <<<TEXT
87
+ Simple and minimalistic job queue (or deferred-task) system.
88
+
89
+ Available Tasks:
90
+ $ tasks
91
+ TEXT ;
92
+ return $ text ;
102
93
}
103
94
104
95
/**
@@ -110,7 +101,7 @@ public function main() {
110
101
public function add () {
111
102
if (count ($ this ->args ) < 1 ) {
112
103
$ this ->out ('Please call like this: ' );
113
- $ this ->out (' cake Queue.Queue add <taskname> ' );
104
+ $ this ->out (' bin/ cake queue add <taskname> ' );
114
105
$ this ->_displayAvailableTasks ();
115
106
116
107
return ;
@@ -209,11 +200,13 @@ public function runworker() {
209
200
210
201
try {
211
202
$ data = json_decode ($ queuedTask ['data ' ], true );
212
- $ return = $ this ->{$ taskname }->run ((array )$ data , $ queuedTask ['id ' ]);
203
+ /* @var \Queue\Shell\Task\QueueTask $task */
204
+ $ task = $ this ->{$ taskname };
205
+ $ return = $ task ->run ((array )$ data , $ queuedTask ['id ' ]);
213
206
214
207
$ failureMessage = null ;
215
- if (! empty ( $ this ->{ $ taskname }-> failureMessage ) ) {
216
- $ failureMessage = $ this ->{ $ taskname } ->failureMessage ;
208
+ if ($ task -> failureMessage ) {
209
+ $ failureMessage = $ task ->failureMessage ;
217
210
}
218
211
} catch (Exception $ e ) {
219
212
$ return = false ;
@@ -297,6 +290,12 @@ public function settings() {
297
290
$ this ->out ('Current Settings: ' );
298
291
$ conf = (array )Configure::read ('Queue ' );
299
292
foreach ($ conf as $ key => $ val ) {
293
+ if ($ val === false ) {
294
+ $ val = 'no ' ;
295
+ }
296
+ if ($ val === true ) {
297
+ $ val = 'yes ' ;
298
+ }
300
299
$ this ->out ('* ' . $ key . ': ' . print_r ($ val , true ));
301
300
}
302
301
}
@@ -334,7 +333,7 @@ public function stats() {
334
333
* @return void
335
334
*/
336
335
public function install () {
337
- $ this ->out ('Run `cake Schema create -p Queue` ' );
336
+ $ this ->out ('Run `cake Migrations.migrate -p Queue` ' );
338
337
}
339
338
340
339
/**
@@ -343,7 +342,7 @@ public function install() {
343
342
* @return void
344
343
*/
345
344
public function uninstall () {
346
- $ this ->out ('Remove all workers and then delete the two tables. ' );
345
+ $ this ->out ('Remove all workers and cronjobs and then delete the Queue plugin tables. ' );
347
346
}
348
347
349
348
/**
@@ -376,7 +375,7 @@ public function getOptionParser() {
376
375
];
377
376
378
377
return parent ::getOptionParser ()
379
- ->description (' Simple and minimalistic job queue (or deferred-task) system. ' )
378
+ ->description ($ this -> _getDescription () )
380
379
->addSubcommand ('clean ' , [
381
380
'help ' => 'Remove old jobs (cleanup) ' ,
382
381
'parser ' => $ subcommandParser ,
@@ -397,8 +396,12 @@ public function getOptionParser() {
397
396
'help ' => 'Stats ' ,
398
397
'parser ' => $ subcommandParserFull ,
399
398
])
399
+ ->addSubcommand ('settings ' , [
400
+ 'help ' => 'Settings ' ,
401
+ 'parser ' => $ subcommandParserFull ,
402
+ ])
400
403
->addSubcommand ('reset ' , [
401
- 'help ' => 'Stats ' ,
404
+ 'help ' => 'Manually reset (failed) jobs for re-run. ' ,
402
405
'parser ' => $ subcommandParserFull ,
403
406
])
404
407
->addSubcommand ('runworker ' , [
0 commit comments