Skip to content

Commit

Permalink
Merge pull request #6 from CakeDC/feature/cake5-improvements
Browse files Browse the repository at this point in the history
Feature/cake5 improvements
  • Loading branch information
arusinowski authored Dec 10, 2024
2 parents 97adf6a + cd50827 commit 9d081cd
Show file tree
Hide file tree
Showing 12 changed files with 572 additions and 58 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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.0] - 2024-12-10
* added commands to purge queues and test queues
* fixed test queue template path
* changed `queue_monitor purge` to `queue-monitor purge-logs`
* changed `queue_monitor notify` to `queue-monitor notify
* changed default configuration of `purgeLogsOlderThanDays` to 7 days instead of 30

## [2.0.2] - 2024-12-09
* ported fixes and enhancement from version 1.x
* fixed handling `QueueMonitor.purgeLogsOlderThanDays` in Purge command
* added `QueueMonitor.disabled` option
* added support for disabling queue monitor commands
* updated README.md
* decreased log level when queue monitor is disabled
* replaced saveOrFail with save

## [2.0.1] - 2024-05-14
### Fixed
- Removed TimestampBehavior from LogsTable to avoid problems when TimestampBehavior is overriden

## [2.0] - 2024-04-17

### Added
Expand Down
83 changes: 45 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Versions and branches
| CakePHP | CakeDC Queue Monitor Plugin | Tag | Notes |
|:-------:|:--------------------------------------------------------------------------:|:------------:|:-------|
| ^5.0 | [2.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/2.next-cake5) | 2.next-cake5 | stable |
| ^5.0 | [2.1.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/2.next-cake5) | 2.next-cake5 | stable |
| ^4.4 | [1.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/1.next-cake4) | 1.next-cake4 | stable |

## Overview
Expand All @@ -26,28 +26,14 @@ composer require cakedc/queue-monitor
```

## Configuration

Add QueueMonitorPlugin to your `Application::bootstrap`:
```php
use Cake\Http\BaseApplication;
use CakeDC\QueueMonitor\QueueMonitorPlugin;

class Application extends BaseApplication
{
// ...

public function bootstrap(): void
{
parent::bootstrap();

$this->addPlugin(QueueMonitorPlugin::class);
}

// ...
}

Add QueueMonitorPlugin to your application by running command:
```shell
bin/cake plugin load CakeDC/QueueMonitor
```
Run the required migrations
```shell
bin/cake migrations migrate -p CakeDC/QueueMonitor
```

Set up the QueueMonitor configuration in your `config/app_local.php`:
```php
// ...
Expand All @@ -58,28 +44,22 @@ Set up the QueueMonitor configuration in your `config/app_local.php`:

// mailer config, the default is `default` mailer, you can ommit
// this setting if you use default value
'mailerConfig' => 'myCustomMailer',
'mailerConfig' => 'default',

// the default is 30 minutes, you can ommit this setting if you
// use the default value
'longJobInMinutes' => 45,
// the default is 30 minutes, you can ommit this setting if you use the default value
'longJobInMinutes' => 30,

// the default is 30 days, you can ommit this setting if you
// the default is 7 days, you can ommit this setting if you use the default value
// its advised to set this value correctly after queue usage analysis to avoid
// high space usage in db
'purgeLogsOlderThanDays' => 10,
'purgeLogsOlderThanDays' => 7,

// comma separated list of recipients of notification about long running queue jobs
'notificationRecipients' => '[email protected],[email protected],[email protected]',
],
// ...
```

Run the required migrations
```shell
bin/cake migrations migrate -p CakeDC/QueueMonitor
```

For each queue configuration add `listener` setting
```php
// ...
Expand All @@ -95,19 +75,46 @@ For each queue configuration add `listener` setting

## Notification command

To set up notifications when there are long running or possible stuck jobs please use command
To set up notifications when there are jobs running for a long time or jobs that may be stuck and blocking the queue
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
to use it as a cronjob
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.

## Purge queues command
To purge the content of a specified queue you can use the purge queue command:
```shell
bin/cake queue-monitor purge-queue your-queue-name

```

The above command will remove all pending queue jobs from the specified queue.

To purge all queues you can use command:

```shell
bin/cake queue-monitor purge-queue --all

```

## Purge command
## Purge Logs command

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-logs
```

This command will purge logs older than value specified in `QueueMonitor.purgeLogsOlderThanDays`, the value is in
Expand Down
12 changes: 10 additions & 2 deletions src/Command/NotifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ public function __construct(
*/
public static function defaultName(): string
{
return 'queue_monitor notify';
return 'queue-monitor notify';
}

/**
* @inheritDoc
*/
public static function getDescription(): string
{
return __('Queue Monitoring notifier');
}

/**
Expand All @@ -57,7 +65,7 @@ public static function defaultName(): string
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
return parent::buildOptionParser($parser)
->setDescription(__('Queue Monitoring notifier'));
->setDescription(self::getDescription());
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/Command/PurgeCommand.php → src/Command/PurgeLogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
use function Cake\I18n\__;

/**
* Purge command.
* Purge Logs command.
*/
final class PurgeCommand extends Command
final class PurgeLogsCommand extends Command
{
use DisableTrait;
use LogTrait;

private const DEFAULT_PURGE_DAYS_OLD = 30;
private const DEFAULT_PURGE_DAYS_OLD = 7;

/**
* Constructor
Expand All @@ -48,7 +48,15 @@ public function __construct(
*/
public static function defaultName(): string
{
return 'queue_monitor purge';
return 'queue-monitor purge-logs';
}

/**
* @inheritDoc
*/
public static function getDescription(): string
{
return __('Queue Monitoring log purger');
}

/**
Expand All @@ -57,7 +65,7 @@ public static function defaultName(): string
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
return parent::buildOptionParser($parser)
->setDescription(__('Queue Monitoring log purger'));
->setDescription(self::getDescription());
}

/**
Expand All @@ -73,6 +81,7 @@ public function execute(Arguments $args, ConsoleIo $io)

return self::CODE_SUCCESS;
}

$purgeLogsOlderThanDays = (int)Configure::read(
'QueueMonitor.purgeLogsOlderThanDays',
self::DEFAULT_PURGE_DAYS_OLD
Expand Down
Loading

0 comments on commit 9d081cd

Please sign in to comment.