Skip to content

Commit b119a74

Browse files
author
dereuromark
committed
Add settings.
1 parent 7c058b2 commit b119a74

9 files changed

+76
-77
lines changed

docs/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ Run the following using the CakePHP shell:
7878

7979
* Display Help message:
8080

81-
bin/cake Queue.Queue
81+
bin/cake queue
8282

8383
* Try to call the cli add() function on a task:
8484

85-
bin/cake Queue.Queue add <TaskName>
85+
bin/cake queue add <TaskName>
8686

8787
Tasks may or may not provide this functionality.
8888

8989
* Run a queue worker, which will look for a pending task it can execute:
9090

91-
bin/cake Queue.Queue runworker
91+
bin/cake queue runworker
9292

9393
The worker will always try to find jobs matching its installed Tasks.
9494

@@ -159,7 +159,7 @@ to start a new worker.
159159

160160
The following example uses "crontab":
161161

162-
*/10 * * * * cd /full/path/to/app && bin/cake Queue.Queue runworker
162+
*/10 * * * * cd /full/path/to/app && bin/cake queue runworker
163163

164164
Make sure you use `crontab -e -u www-data` to set it up as `www-data` user, and not as root etc.
165165

@@ -225,3 +225,9 @@ is useful when dealing with emails which serialization would overflow database `
225225
### Killing workers
226226
//TODO
227227

228+
## Contributing
229+
I am looking forward to your contributions.
230+
231+
There are a few guidelines that I need contributors to follow:
232+
* Coding standards (`./sniff` to check and `./sniff -f` to fix)
233+
* Passing tests (`php phpunit.phar`)

sniff

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Make sure this file is executable
4+
# chmod +x sniff
5+
6+
if [ `echo "$@" | grep '\-\-fix'` ] || [ `echo "$@" | grep '\-f'` ]; then
7+
FIX=1
8+
else
9+
FIX=0
10+
fi
11+
12+
if [ "$FIX" = 1 ]; then
13+
# Sniff and fix
14+
vendor/bin/phpcbf --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=cakephp-queue/vendor/,tmp/,logs/,tests/test_files/,config/Migrations/ --extensions=php -v -f ./
15+
else
16+
# Sniff only
17+
vendor/bin/phpcs --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=cakephp-queue/vendor/,tmp/,logs/,tests/test_files/,config/Migrations/ --extensions=php -v ./
18+
fi

src/Shell/QueueShell.php

+37-34
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class QueueShell extends Shell {
3030
public $modelClass = 'Queue.QueuedJobs';
3131

3232
/**
33-
* @var array
33+
* @var array|null
3434
*/
3535
protected $_taskConf;
3636

3737
/**
3838
* @var bool
3939
*/
40-
protected $_exit;
40+
protected $_exit = false;
4141

4242
/**
4343
* Overwrite shell initialize to dynamically load all Queue Related Tasks.
@@ -74,31 +74,22 @@ public function initialize() {
7474
}
7575

7676
/**
77-
* Output some basic usage Info.
78-
*
79-
* @return void
77+
* @return string
8078
*/
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;
10293
}
10394

10495
/**
@@ -110,7 +101,7 @@ public function main() {
110101
public function add() {
111102
if (count($this->args) < 1) {
112103
$this->out('Please call like this:');
113-
$this->out(' cake Queue.Queue add <taskname>');
104+
$this->out(' bin/cake queue add <taskname>');
114105
$this->_displayAvailableTasks();
115106

116107
return;
@@ -209,11 +200,13 @@ public function runworker() {
209200

210201
try {
211202
$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']);
213206

214207
$failureMessage = null;
215-
if (!empty($this->{$taskname}->failureMessage)) {
216-
$failureMessage = $this->{$taskname}->failureMessage;
208+
if ($task->failureMessage) {
209+
$failureMessage = $task->failureMessage;
217210
}
218211
} catch (Exception $e) {
219212
$return = false;
@@ -297,6 +290,12 @@ public function settings() {
297290
$this->out('Current Settings:');
298291
$conf = (array)Configure::read('Queue');
299292
foreach ($conf as $key => $val) {
293+
if ($val === false) {
294+
$val = 'no';
295+
}
296+
if ($val === true) {
297+
$val = 'yes';
298+
}
300299
$this->out('* ' . $key . ': ' . print_r($val, true));
301300
}
302301
}
@@ -334,7 +333,7 @@ public function stats() {
334333
* @return void
335334
*/
336335
public function install() {
337-
$this->out('Run `cake Schema create -p Queue`');
336+
$this->out('Run `cake Migrations.migrate -p Queue`');
338337
}
339338

340339
/**
@@ -343,7 +342,7 @@ public function install() {
343342
* @return void
344343
*/
345344
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.');
347346
}
348347

349348
/**
@@ -376,7 +375,7 @@ public function getOptionParser() {
376375
];
377376

378377
return parent::getOptionParser()
379-
->description('Simple and minimalistic job queue (or deferred-task) system.')
378+
->description($this->_getDescription())
380379
->addSubcommand('clean', [
381380
'help' => 'Remove old jobs (cleanup)',
382381
'parser' => $subcommandParser,
@@ -397,8 +396,12 @@ public function getOptionParser() {
397396
'help' => 'Stats',
398397
'parser' => $subcommandParserFull,
399398
])
399+
->addSubcommand('settings', [
400+
'help' => 'Settings',
401+
'parser' => $subcommandParserFull,
402+
])
400403
->addSubcommand('reset', [
401-
'help' => 'Stats',
404+
'help' => 'Manually reset (failed) jobs for re-run.',
402405
'parser' => $subcommandParserFull,
403406
])
404407
->addSubcommand('runworker', [

src/Shell/Task/QueueExampleTask.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ class QueueExampleTask extends QueueTask {
2626
*/
2727
public $retries = 1;
2828

29-
/**
30-
* Stores any failure messages triggered during run()
31-
*
32-
* @var string
33-
*/
34-
public $failureMessage = '';
35-
3629
/**
3730
* Example add functionality.
3831
* Will create one example job in the queue, which later will be executed using run();
@@ -47,7 +40,7 @@ public function add() {
4740
$this->out('This job will only produce some console output on the worker that it runs on.');
4841
$this->out(' ');
4942
$this->out('To run a Worker use:');
50-
$this->out(' cake Queue.Queue runworker');
43+
$this->out(' bin/cake queue runworker');
5144
$this->out(' ');
5245
$this->out('You can find the sourcecode of this task in: ');
5346
$this->out(__FILE__);

src/Shell/Task/QueueExecuteTask.php

-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ class QueueExecuteTask extends QueueTask {
2626
*/
2727
public $retries = 1;
2828

29-
/**
30-
* Stores any failure messages triggered during run()
31-
*
32-
* @var string
33-
*/
34-
public $failureMessage = '';
35-
3629
/**
3730
* Add functionality.
3831
* Will create one example job in the queue, which later will be executed using run();

src/Shell/Task/QueueLongExampleTask.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class QueueLongExampleTask extends QueueTask {
2828
*/
2929
public $retries = 1;
3030

31-
/**
32-
* Stores any failure messages triggered during run()
33-
*
34-
* @var string
35-
*/
36-
public $failureMessage = '';
37-
3831
/**
3932
* Example add functionality.
4033
* Will create one example job in the queue, which later will be executed using run();
@@ -49,7 +42,7 @@ public function add() {
4942
$this->out('This job will need at least 2 minutes to complete.');
5043
$this->out(' ');
5144
$this->out('To run a Worker use:');
52-
$this->out(' cake Queue.Queue runworker');
45+
$this->out(' bin/cake queue runworker');
5346
$this->out(' ');
5447
$this->out('You can find the sourcecode of this task in:');
5548
$this->out(__FILE__);

src/Shell/Task/QueueRetryExampleTask.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class QueueRetryExampleTask extends QueueTask {
2828
*/
2929
public $retries = 5;
3030

31-
/**
32-
* Stores any failure messages triggered during run()
33-
*
34-
* @var string
35-
*/
36-
public $failureMessage = '';
37-
3831
/**
3932
* Constructs this Shell instance.
4033
*
@@ -60,7 +53,7 @@ public function add() {
6053
$this->out('This job will only produce some console output on the worker that it runs on.');
6154
$this->out(' ');
6255
$this->out('To run a Worker use:');
63-
$this->out(' cake Queue.Queue runworker');
56+
$this->out(' bin/cake queue runworker');
6457
$this->out(' ');
6558
$this->out('You can find the sourcecode of this task in: ');
6659
$this->out(__FILE__);

src/Shell/Task/QueueSuperExampleTask.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ class QueueSuperExampleTask extends QueueTask {
2626
*/
2727
public $retries = 1;
2828

29-
/**
30-
* Stores any failure messages triggered during run()
31-
*
32-
* @var string
33-
*/
34-
public $failureMessage = '';
35-
3629
/**
3730
* SuperExample add functionality.
3831
* Will create one example job in the queue, which later will be executed using run();
@@ -48,7 +41,7 @@ public function add() {
4841
$this->out('This job will only produce some console output on the worker that it runs on.');
4942
$this->out(' ');
5043
$this->out('To run a Worker use:');
51-
$this->out(' cake Queue.Queue runworker');
44+
$this->out(' bin/cake queue runworker');
5245
$this->out(' ');
5346
$this->out('You can find the sourcecode of this task in: ');
5447
$this->out(__FILE__);

src/Shell/Task/QueueTask.php

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class QueueTask extends Shell {
4141
*/
4242
public $retries = 4;
4343

44+
/**
45+
* Stores any failure messages triggered during run()
46+
*
47+
* @var string|null
48+
*/
49+
public $failureMessage = null;
50+
4451
/**
4552
* @param \Cake\Console\ConsoleIo|null $io IO
4653
*/

0 commit comments

Comments
 (0)