-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0357744
commit b40f50a
Showing
7 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ For each queue configuration add `listener` setting | |
|
||
To set up notifications when there are long running or possible stuck jobs please use command | ||
```shell | ||
bin/cake queue_monitor notify | ||
bin/cake queue-monitor notify | ||
``` | ||
|
||
This command will send notification emails to recipients specified in `QueueMonitor.notificationRecipients`. Best is | ||
|
@@ -107,12 +107,22 @@ to use it as a cronjob | |
|
||
The logs table may grow overtime, to keep it slim you can use the purge command: | ||
```shell | ||
bin/cake queue_monitor purge | ||
bin/cake queue-monitor purge | ||
``` | ||
|
||
This command will purge logs older than value specified in `QueueMonitor.purgeLogsOlderThanDays`, the value is in | ||
days, the default is 30 days. Best is to use it as a cronjob | ||
|
||
## Test Enqueue command | ||
|
||
To quickly test if all queues are running correctly please run this command (replace `[email protected]` with working | ||
email address: | ||
```shell | ||
bin/cake queue-monitor test-enqueue [email protected] | ||
``` | ||
|
||
This command will send the command through all configured queues. | ||
|
||
## Important | ||
|
||
Make sure your Job classes have a property value of maxAttempts because if it's missing, the log table can quickly | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\QueueMonitor\Command; | ||
|
||
use Cake\Command\Command; | ||
use Cake\Console\Arguments; | ||
use Cake\Console\ConsoleIo; | ||
use Cake\Console\ConsoleOptionParser; | ||
use Cake\Core\Configure; | ||
use Cake\Mailer\MailerAwareTrait; | ||
use Cake\Validation\Validation; | ||
|
||
/** | ||
* Test Enqueue Command | ||
*/ | ||
final class TestEnqueueCommand extends Command | ||
{ | ||
use MailerAwareTrait; | ||
|
||
private const ARGUMENT_EMAIL = 'email'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function defaultName(): string | ||
{ | ||
return 'queue-monitor test-enqueue'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getDescription(): string | ||
{ | ||
return __('Enqueue test email'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser | ||
{ | ||
return parent::buildOptionParser($parser) | ||
->setDescription(__('Enqueue test email')) | ||
->addArgument($this::ARGUMENT_EMAIL, [ | ||
'help' => __('Email to send to'), | ||
'required' => true, | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(Arguments $args, ConsoleIo $io) | ||
{ | ||
$email = $args->getArgument(self::ARGUMENT_EMAIL); | ||
if (!Validation::email($email)) { | ||
$io->error(__('Invalid email')); | ||
|
||
return $this::CODE_ERROR; | ||
} | ||
|
||
collection(Configure::read('Queue', [])) | ||
->each(function ( | ||
array $queueConfig, | ||
string $queueConfigKey | ||
) use ( | ||
$email, | ||
$io | ||
): void { | ||
/** @var \CakeDC\QueueMonitor\Mailer\TestEnqueueMailer $mailer */ | ||
$mailer = $this->getMailer('QueueMonitor.TestEnqueue'); | ||
/** @uses \CakeDC\QueueMonitor\Mailer\TestEnqueueMailer::testEnqueue() */ | ||
$mailer->push( | ||
action: $mailer::SEND_TEST_ENQUEUE, | ||
args: [ | ||
$email, | ||
$queueConfigKey, | ||
], | ||
options: [ | ||
'config' => $queueConfigKey, | ||
] | ||
); | ||
$io->info(__( | ||
'Enqueued test email `{0}` in queue `{1}`', | ||
$email, | ||
$queueConfigKey | ||
)); | ||
}); | ||
|
||
return $this::CODE_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2010 - 2024, Cake Development Corporation (https://www.cakedc.com) | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace CakeDC\QueueMonitor\Mailer; | ||
|
||
use Cake\Core\Configure; | ||
use Cake\Mailer\Mailer; | ||
use Cake\Mailer\Message; | ||
use Cake\Queue\Mailer\QueueTrait; | ||
|
||
/** | ||
* Test Enqueue Mailer | ||
*/ | ||
class TestEnqueueMailer extends Mailer | ||
{ | ||
use QueueTrait; | ||
|
||
public const SEND_TEST_ENQUEUE = 'testEnqueue'; | ||
|
||
/** | ||
* Mailer's name. | ||
* | ||
* @var string | ||
*/ | ||
public static $name = 'TestEnqueue'; | ||
|
||
/** | ||
* Send test email | ||
*/ | ||
public function testEnqueue(string $emailAddress, ?string $queueConfig = 'default'): void | ||
{ | ||
$this | ||
->setProfile(Configure::read('QueueMonitor.mailerConfig', 'default')) | ||
->setTo($emailAddress) | ||
->setSubject(__('Test enqueue from queue `{0}`', $queueConfig)) | ||
->setEmailFormat(Message::MESSAGE_BOTH) | ||
->viewBuilder() | ||
->disableAutoLayout() | ||
->setTemplate('QueueMonitor.test_enqueue'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
?> | ||
|
||
Test email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
?> | ||
|
||
Test email |