Skip to content

Commit 09820e0

Browse files
authored
Merge pull request #1 from CakeDC/feature/disable-option
added `QueueMonitor.enabled` option
2 parents 5ee5829 + af51110 commit 09820e0

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

.gitattributes

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Define the line ending behavior of the different file extensions
2+
# Set default behavior, in case users don't have core.autocrlf set.
3+
* text text=auto eol=lf
4+
5+
.php diff=php
6+
7+
# Declare files that will always have CRLF line endings on checkout.
8+
*.bat eol=crlf
9+
10+
# Declare files that will always have LF line endings on checkout.
11+
*.pem eol=lf
12+
13+
# Denote all files that are truly binary and should not be modified.
14+
*.png binary
15+
*.jpg binary
16+
*.gif binary
17+
*.ico binary
18+
*.mo binary
19+
*.pdf binary
20+
*.phar binary
21+
*.woff binary
22+
*.woff2 binary
23+
*.ttf binary
24+
*.otf binary
25+
*.eot binary
26+
27+
# Remove files for archives generated using `git archive`
28+
.github export-ignore
29+
.phive export-ignore
30+
contrib export-ignore
31+
tests/test_app export-ignore
32+
tests/TestCase export-ignore
33+
34+
.editorconfig export-ignore
35+
.gitattributes export-ignore
36+
.gitignore export-ignore
37+
.mailmap export-ignore
38+
.stickler.yml export-ignore
39+
Makefile export-ignore
40+
phpcs.xml export-ignore
41+
phpstan.neon.dist export-ignore
42+
phpstan-baseline.neon export-ignore
43+
phpunit.xml.dist export-ignore
44+
psalm.xml export-ignore
45+
psalm-baseline.xml export-ignore

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Set up the QueueMonitor configuration in your `config/app_local.php`:
5252
```php
5353
// ...
5454
'QueueMonitor' => [
55+
// With this setting you can enable or disable the queue monitoring without
56+
// restarting the workers, the queue monitoring is enabled by default
57+
'disable' => false,
58+
5559
// mailer config, the default is `default` mailer, you can ommit
5660
// this setting if you use default value
5761
'mailerConfig' => 'myCustomMailer',

src/Listener/QueueMonitorListener.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
namespace CakeDC\QueueMonitor\Listener;
1414

15+
use Cake\Core\Configure;
1516
use Cake\Event\EventInterface;
1617
use Cake\Event\EventListenerInterface;
1718
use Cake\I18n\FrozenTime;
@@ -74,6 +75,10 @@ public function implementedEvents(): array
7475
*/
7576
public function handleException(EventInterface $event, ?Message $message, ?Throwable $exception = null): void
7677
{
78+
if ($this->isDisabled()) {
79+
return;
80+
}
81+
7782
try {
7883
$message = $this->validateQueueMessage($message);
7984

@@ -104,6 +109,10 @@ public function handleException(EventInterface $event, ?Message $message, ?Throw
104109
*/
105110
public function handleMessageEvent(EventInterface $event, ?Message $message): void
106111
{
112+
if ($this->isDisabled()) {
113+
return;
114+
}
115+
107116
try {
108117
$message = $this->validateQueueMessage($message);
109118

@@ -123,6 +132,10 @@ public function handleMessageEvent(EventInterface $event, ?Message $message): vo
123132
*/
124133
public function handleSeen(EventInterface $event, ?QueueMessage $queueMessage): void
125134
{
135+
if ($this->isDisabled()) {
136+
return;
137+
}
138+
126139
try {
127140
$queueMessage = $this->validateInteropQueueMessage($queueMessage);
128141
$messageBody = json_decode($queueMessage->getBody(), true);
@@ -213,4 +226,12 @@ public function validateInteropQueueMessage(?QueueMessage $queueMessage): QueueM
213226

214227
return $queueMessage;
215228
}
229+
230+
/**
231+
* Check if queue monitoring is disabled by configuration
232+
*/
233+
private function isDisabled(): bool
234+
{
235+
return (bool)Configure::read('QueueMonitor.disabled', false);
236+
}
216237
}

0 commit comments

Comments
 (0)