Skip to content

Commit 4de7db1

Browse files
committed
Add descr.
1 parent 1d41261 commit 4de7db1

11 files changed

Lines changed: 90 additions & 17 deletions

src/Controller/Admin/QueueController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function index() {
6464
$tasks = $taskFinder->all();
6565
$addableTasks = $taskFinder->allAddable(AddFromBackendInterface::class);
6666

67+
$taskDescriptions = [];
68+
foreach ($tasks as $task => $className) {
69+
/** @var \Queue\Queue\Task $taskObject */
70+
$taskObject = new $className();
71+
$taskDescriptions[$task] = $taskObject->description();
72+
}
73+
6774
$servers = $QueueProcesses->serverList();
6875
$workers = $status ? $status['workers'] : 0;
6976

@@ -95,6 +102,7 @@ public function index() {
95102
'status',
96103
'tasks',
97104
'addableTasks',
105+
'taskDescriptions',
98106
'servers',
99107
'workers',
100108
'pendingJobs',

src/Queue/Task.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@ public static function taskName(): string {
114114
return Config::taskName($class);
115115
}
116116

117+
/**
118+
* Returns a human-readable description of what this task does.
119+
*
120+
* Override this in your task to provide a description that will be shown
121+
* as a tooltip in the admin backend.
122+
*
123+
* @return string|null
124+
*/
125+
public function description(): ?string {
126+
return null;
127+
}
128+
117129
}

src/Queue/Task/CostsExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class CostsExampleTask extends Task implements AddInterface, AddFromBackendInter
3333
public function add(?string $data): void {
3434
$this->io->out('CakePHP Queue CostsExample task.');
3535
$this->io->hr();
36+
$this->io->out($this->description());
3637
$this->io->out('I will now add an example Job into the Queue.');
37-
$this->io->out('This job cannot run more than once per server (across all its workers).');
38-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
3938
$this->io->out(' ');
4039
$this->io->out('To run a Worker use:');
4140
$this->io->out(' bin/cake queue run');
@@ -48,6 +47,13 @@ public function add(?string $data): void {
4847
$this->io->success('OK, job created, now run the worker');
4948
}
5049

50+
/**
51+
* @return string|null
52+
*/
53+
public function description(): ?string {
54+
return __d('queue', 'Demonstrates cost management to prevent server overload');
55+
}
56+
5157
/**
5258
* CostsExample run function.
5359
* This function is executed, when a worker is executing a task.

src/Queue/Task/ExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ class ExampleTask extends Task implements AddInterface, AddFromBackendInterface
3636
public function add(?string $data): void {
3737
$this->io->out('CakePHP Queue Example task.');
3838
$this->io->hr();
39-
$this->io->out('This is a very simple example of a QueueTask.');
39+
$this->io->out($this->description());
4040
$this->io->out('I will now add an example Job into the Queue.');
41-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
4241
$this->io->out(' ');
4342
$this->io->out('To run a Worker use:');
4443
$this->io->out(' bin/cake queue run');
@@ -51,6 +50,13 @@ public function add(?string $data): void {
5150
$this->io->success('OK, job created, now run the worker');
5251
}
5352

53+
/**
54+
* @return string|null
55+
*/
56+
public function description(): ?string {
57+
return __d('queue', 'Simple task that outputs to console');
58+
}
59+
5460
/**
5561
* Example run function.
5662
* This function is executed, when a worker is executing a task.

src/Queue/Task/ExceptionExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class ExceptionExampleTask extends Task implements AddInterface, AddFromBackendI
3232
public function add(?string $data): void {
3333
$this->io->out('CakePHP Queue ExceptionExample task.');
3434
$this->io->hr();
35-
$this->io->out('This is a very simple example of a QueueTask and how exceptions are handled.');
35+
$this->io->out($this->description());
3636
$this->io->out('I will now add an example Job into the Queue.');
37-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
3837
$this->io->out(' ');
3938
$this->io->out('To run a Worker use:');
4039
$this->io->out(' bin/cake queue run');
@@ -47,6 +46,13 @@ public function add(?string $data): void {
4746
$this->io->success('OK, job created, now run the worker');
4847
}
4948

49+
/**
50+
* @return string|null
51+
*/
52+
public function description(): ?string {
53+
return __d('queue', 'Demonstrates exception handling (always fails)');
54+
}
55+
5056
/**
5157
* Example run function.
5258
* This function is executed, when a worker is executing a task.

src/Queue/Task/MonitorExampleTask.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class MonitorExampleTask extends Task implements AddInterface, AddFromBackendInt
3838
public function add(?string $data): void {
3939
$this->io->out('CakePHP Queue MonitorExample task.');
4040
$this->io->hr();
41-
$this->io->out('This is an example of doing some server monitor tasks and logging.');
42-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
41+
$this->io->out($this->description());
42+
$this->io->out('I will now add an example Job into the Queue.');
4343
$this->io->out(' ');
4444
$this->io->out('To run a Worker use:');
4545
$this->io->out(' bin/cake queue run');
@@ -52,6 +52,13 @@ public function add(?string $data): void {
5252
$this->io->success('OK, job created, now run the worker');
5353
}
5454

55+
/**
56+
* @return string|null
57+
*/
58+
public function description(): ?string {
59+
return __d('queue', 'Logs server memory and PHP info');
60+
}
61+
5562
/**
5663
* MonitorExample run function.
5764
* This function is executed, when a worker is executing a task.

src/Queue/Task/ProgressExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ class ProgressExampleTask extends Task implements AddInterface, AddFromBackendIn
3636
public function add(?string $data): void {
3737
$this->io->out('CakePHP Queue ProgressExample task.');
3838
$this->io->hr();
39-
$this->io->out('This is a very simple but long running example of a QueueTask.');
39+
$this->io->out($this->description());
4040
$this->io->out('I will now add the Job into the Queue.');
41-
$this->io->out('This job will need at least 2 minutes to complete.');
4241
$this->io->out(' ');
4342
$this->io->out('To run a Worker use:');
4443
$this->io->out(' bin/cake queue run');
@@ -54,6 +53,13 @@ public function add(?string $data): void {
5453
$this->io->success('OK, job created, now run the worker');
5554
}
5655

56+
/**
57+
* @return string|null
58+
*/
59+
public function description(): ?string {
60+
return __d('queue', 'Long-running task (~2 min) with progress bar updates');
61+
}
62+
5763
/**
5864
* Example run function.
5965
* This function is executed, when a worker is executing a task.

src/Queue/Task/RetryExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ public static function init(): bool {
6868
public function add(?string $data): void {
6969
$this->io->out('CakePHP Queue RetryExample task.');
7070
$this->io->hr();
71-
$this->io->out('This is a very simple example of a QueueTask and how retries work.');
71+
$this->io->out($this->description());
7272
$this->io->out('I will now add an example Job into the Queue.');
73-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
7473
$this->io->out(' ');
7574
$this->io->out('To run a Worker use:');
7675
$this->io->out(' bin/cake queue run');
@@ -88,6 +87,13 @@ public function add(?string $data): void {
8887
$this->io->success('OK, job created, now run the worker');
8988
}
9089

90+
/**
91+
* @return string|null
92+
*/
93+
public function description(): ?string {
94+
return __d('queue', 'Demonstrates retry behavior (fails 3x, succeeds on 4th)');
95+
}
96+
9197
/**
9298
* Example run function.
9399
* This function is executed, when a worker is executing a task.

src/Queue/Task/SuperExampleTask.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ class SuperExampleTask extends Task implements AddInterface, AddFromBackendInter
3636
public function add(?string $data): void {
3737
$this->io->out('CakePHP Queue SuperExample task.');
3838
$this->io->hr();
39-
$this->io->out('This is a very superb example of a QueueTask.');
39+
$this->io->out($this->description());
4040
$this->io->out('I will now add an example Job into the Queue.');
41-
$this->io->out('It will also create another Example job upon successful execution.');
42-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
4341
$this->io->out(' ');
4442
$this->io->out('To run a Worker use:');
4543
$this->io->out(' bin/cake queue run');
@@ -52,6 +50,13 @@ public function add(?string $data): void {
5250
$this->io->success('OK, job created, now run the worker');
5351
}
5452

53+
/**
54+
* @return string|null
55+
*/
56+
public function description(): ?string {
57+
return __d('queue', 'Creates another Example job upon completion (chaining)');
58+
}
59+
5560
/**
5661
* SuperExample run function.
5762
* This function is executed, when a worker is executing a task.

src/Queue/Task/UniqueExampleTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class UniqueExampleTask extends Task implements AddInterface, AddFromBackendInte
3333
public function add(?string $data): void {
3434
$this->io->out('CakePHP Queue UniqueExample task.');
3535
$this->io->hr();
36+
$this->io->out($this->description());
3637
$this->io->out('I will now add an example Job into the Queue.');
37-
$this->io->out('This job cannot run more than once across all workers.');
38-
$this->io->out('This job will only produce some console output on the worker that it runs on.');
3938
$this->io->out(' ');
4039
$this->io->out('To run a Worker use:');
4140
$this->io->out(' bin/cake queue run');
@@ -48,6 +47,13 @@ public function add(?string $data): void {
4847
$this->io->success('OK, job created, now run the worker');
4948
}
5049

50+
/**
51+
* @return string|null
52+
*/
53+
public function description(): ?string {
54+
return __d('queue', 'Only one instance can run at a time across all workers');
55+
}
56+
5157
/**
5258
* UniqueExample run function.
5359
* This function is executed, when a worker is executing a task.

0 commit comments

Comments
 (0)