-
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.
initial commit of CakePHP4.4 version
- Loading branch information
1 parent
f3d0ee4
commit 44ad7b3
Showing
25 changed files
with
1,667 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.bat] | ||
end_of_line = crlf | ||
|
||
[*.yml] | ||
indent_size = 2 | ||
|
||
[*.xml] | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[*.neon] | ||
indent_style = tab |
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,112 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
|
||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
testsuite: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-version: ['8.1', '8.2', '8.3'] | ||
db-type: [sqlite, mysql, pgsql] | ||
prefer-lowest: [''] | ||
|
||
steps: | ||
- name: Setup MySQL latest | ||
if: matrix.db-type == 'mysql' | ||
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql --default-authentication-plugin=mysql_native_password --disable-log-bin | ||
|
||
- name: Setup PostgreSQL latest | ||
if: matrix.db-type == 'pgsql' | ||
run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
extensions: mbstring, intl, apcu, sqlite, pdo_sqlite, pdo_${{ matrix.db-type }}, ${{ matrix.db-type }} | ||
ini-values: apc.enable_cli = 1 | ||
coverage: pcov | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Get date part for cache key | ||
id: key-date | ||
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache composer dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} | ||
|
||
- name: composer install | ||
run: | | ||
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then | ||
composer update --prefer-lowest --prefer-stable | ||
else | ||
composer update | ||
fi | ||
- name: Setup problem matchers for PHPUnit | ||
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql' | ||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
|
||
- name: Run PHPUnit | ||
run: | | ||
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi | ||
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi | ||
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi | ||
vendor/bin/phpunit | ||
cs-stan: | ||
name: Coding Standard & Static Analysis | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.1' | ||
extensions: mbstring, intl, apcu | ||
coverage: none | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Get date part for cache key | ||
id: key-date | ||
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache composer dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} | ||
|
||
- name: composer install | ||
run: composer stan-setup | ||
|
||
- name: Run PHP CodeSniffer | ||
run: composer cs-check | ||
|
||
- name: Run psalm | ||
if: success() || failure() | ||
run: vendor/bin/psalm.phar --output-format=github | ||
|
||
- name: Run phpstan | ||
if: success() || failure() | ||
run: composer stan |
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,18 @@ | ||
# Changelog | ||
|
||
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.0] - 2024-04-17 | ||
|
||
### Added | ||
|
||
- First release for CakePHP 5.0 | ||
|
||
## [1.0] - 2024-04-17 | ||
|
||
### Added | ||
|
||
- First release for CakePHP 4.4 |
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,6 @@ | ||
Contributing | ||
============ | ||
|
||
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to | ||
contribute new features, enhancements or bug fixes to the plugin, please read our | ||
[Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions. |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Cake Development Corporation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,115 @@ | ||
# CakeDC Queue Monitor Plugin for CakePHP | ||
|
||
## 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 | | ||
| ^4.4 | [1.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/1.next-cake4) | 1.next-cake4 | stable | | ||
|
||
## Overview | ||
|
||
The CakeDC Queue Monitor Plugin adds the ability to monitor jobs in queues that are handled by the | ||
[CakePHP Queue Plugin](https://github.com/cakephp/queue). This plugin checks the duration of work of | ||
individual Jobs and sends a notification when this time is exceeded by a configurable value. | ||
|
||
## Requirements | ||
* CakePHP 4.4 | ||
* PHP 8.1+ | ||
|
||
## Installation | ||
|
||
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). | ||
|
||
The recommended way to install composer package is: | ||
``` | ||
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); | ||
} | ||
|
||
// ... | ||
} | ||
|
||
``` | ||
|
||
Set up the QueueMonitor configuration in your `config/app_local.php`: | ||
```php | ||
// ... | ||
'QueueMonitor' => [ | ||
// mailer config, the default is `default` mailer, you can ommit | ||
// this setting if you use default value | ||
'mailerConfig' => 'myCustomMailer', | ||
|
||
// the default is 30 minutes, you can ommit this setting if you | ||
// use the default value | ||
'longJobInMinutes' => 45, | ||
|
||
// the default is 30 days, you can ommit this setting if you | ||
// its advised to set this value correctly after queue usage analysis to avoid | ||
// high space usage in db | ||
'purgeLogsOlderThanDays' => 10, | ||
|
||
// 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 | ||
// ... | ||
'Queue' => [ | ||
'default' => [ | ||
// ... | ||
'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class, | ||
// ... | ||
] | ||
], | ||
// ... | ||
``` | ||
|
||
## Notification command | ||
|
||
To set up notifications when there are long running or possible stuck jobs please use command | ||
```shell | ||
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 | ||
|
||
## Purge command | ||
|
||
The logs table may grow overtime, to keep it slim you can use the purge command: | ||
```shell | ||
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 | ||
|
||
## Important | ||
|
||
Make sure your Job classes have a property value of maxAttempts because if it's missing, the log table can quickly | ||
grow to gigantic size in the event of an uncaught exception in Job, Job is re-queued indefinitely in such a case. |
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,77 @@ | ||
{ | ||
"name": "cakedc/queue-monitor", | ||
"description": "CakeDC Queue Monitor plugin for CakePHP", | ||
"type": "cakephp-plugin", | ||
"license": "MIT", | ||
"keywords": [ | ||
"cakephp", | ||
"queue", | ||
"queue monitoring", | ||
"queue monitor" | ||
], | ||
"homepage": "https://github.com/CakeDC/cakephp-queue-monitor", | ||
"authors": [ | ||
{ | ||
"name": "CakeDC", | ||
"homepage": "https://www.cakedc.com", | ||
"role": "Author" | ||
}, | ||
{ | ||
"name": "Others", | ||
"homepage": "https://github.com/CakeDC/cakephp-queue-monitor/graphs/contributors" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/CakeDC/cakephp-queue-monitor/issues", | ||
"source": "https://github.com/CakeDC/cakephp-queue-monitor" | ||
}, | ||
"require": { | ||
"php": ">=8.1", | ||
"cakephp/cakephp": "^4.4", | ||
"cakephp/queue": "^1.1", | ||
"ext-json": "*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.6", | ||
"cakephp/migrations": "^3.9", | ||
"cakephp/cakephp-codesniffer": "^4.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CakeDC\\QueueMonitor\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"CakeDC\\QueueMonitor\\Test\\": "tests/", | ||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"analyse": [ | ||
"@stan", | ||
"@psalm" | ||
], | ||
"check": [ | ||
"@cs-check", | ||
"@test", | ||
"@analyse" | ||
], | ||
"cs-check": "phpcs -n -p ./src ./tests", | ||
"cs-fix": "phpcbf ./src ./tests", | ||
"test": "phpunit --stderr", | ||
"stan": "phpstan analyse src/", | ||
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ", | ||
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.9.0 psalm/phar:~5.1.0 && mv composer.backup composer.json", | ||
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon", | ||
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/", | ||
"rector": "rector process src/", | ||
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.11.2 && mv composer.backup composer.json", | ||
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} |
Oops, something went wrong.