Skip to content

Commit

Permalink
added QueueMonitor.enabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
arusinowski committed Oct 17, 2024
1 parent 5ee5829 commit af51110
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Define the line ending behavior of the different file extensions
# Set default behavior, in case users don't have core.autocrlf set.
* text text=auto eol=lf

.php diff=php

# Declare files that will always have CRLF line endings on checkout.
*.bat eol=crlf

# Declare files that will always have LF line endings on checkout.
*.pem eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
*.ico binary
*.mo binary
*.pdf binary
*.phar binary
*.woff binary
*.woff2 binary
*.ttf binary
*.otf binary
*.eot binary

# Remove files for archives generated using `git archive`
.github export-ignore
.phive export-ignore
contrib export-ignore
tests/test_app export-ignore
tests/TestCase export-ignore

.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.mailmap export-ignore
.stickler.yml export-ignore
Makefile export-ignore
phpcs.xml export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
phpunit.xml.dist export-ignore
psalm.xml export-ignore
psalm-baseline.xml export-ignore
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Set up the QueueMonitor configuration in your `config/app_local.php`:
```php
// ...
'QueueMonitor' => [
// With this setting you can enable or disable the queue monitoring without
// restarting the workers, the queue monitoring is enabled by default
'disable' => false,

// mailer config, the default is `default` mailer, you can ommit
// this setting if you use default value
'mailerConfig' => 'myCustomMailer',
Expand Down
21 changes: 21 additions & 0 deletions src/Listener/QueueMonitorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace CakeDC\QueueMonitor\Listener;

use Cake\Core\Configure;
use Cake\Event\EventInterface;
use Cake\Event\EventListenerInterface;
use Cake\I18n\FrozenTime;
Expand Down Expand Up @@ -74,6 +75,10 @@ public function implementedEvents(): array
*/
public function handleException(EventInterface $event, ?Message $message, ?Throwable $exception = null): void
{
if ($this->isDisabled()) {
return;
}

try {
$message = $this->validateQueueMessage($message);

Expand Down Expand Up @@ -104,6 +109,10 @@ public function handleException(EventInterface $event, ?Message $message, ?Throw
*/
public function handleMessageEvent(EventInterface $event, ?Message $message): void
{
if ($this->isDisabled()) {
return;
}

try {
$message = $this->validateQueueMessage($message);

Expand All @@ -123,6 +132,10 @@ public function handleMessageEvent(EventInterface $event, ?Message $message): vo
*/
public function handleSeen(EventInterface $event, ?QueueMessage $queueMessage): void
{
if ($this->isDisabled()) {
return;
}

try {
$queueMessage = $this->validateInteropQueueMessage($queueMessage);
$messageBody = json_decode($queueMessage->getBody(), true);
Expand Down Expand Up @@ -213,4 +226,12 @@ public function validateInteropQueueMessage(?QueueMessage $queueMessage): QueueM

return $queueMessage;
}

/**
* Check if queue monitoring is disabled by configuration
*/
private function isDisabled(): bool
{
return (bool)Configure::read('QueueMonitor.disabled', false);
}
}

0 comments on commit af51110

Please sign in to comment.