Skip to content

Commit 44ad7b3

Browse files
committed
initial commit of CakePHP4.4 version
1 parent f3d0ee4 commit 44ad7b3

25 files changed

+1667
-0
lines changed

.editorconfig

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.bat]
14+
end_of_line = crlf
15+
16+
[*.yml]
17+
indent_size = 2
18+
19+
[*.xml]
20+
indent_size = 2
21+
22+
[Makefile]
23+
indent_style = tab
24+
25+
[*.neon]
26+
indent_style = tab

.github/workflows/ci.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
6+
pull_request:
7+
branches:
8+
- '*'
9+
10+
jobs:
11+
testsuite:
12+
runs-on: ubuntu-22.04
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-version: ['8.1', '8.2', '8.3']
17+
db-type: [sqlite, mysql, pgsql]
18+
prefer-lowest: ['']
19+
20+
steps:
21+
- name: Setup MySQL latest
22+
if: matrix.db-type == 'mysql'
23+
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
24+
25+
- name: Setup PostgreSQL latest
26+
if: matrix.db-type == 'pgsql'
27+
run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres
28+
29+
- uses: actions/checkout@v4
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-version }}
35+
extensions: mbstring, intl, apcu, sqlite, pdo_sqlite, pdo_${{ matrix.db-type }}, ${{ matrix.db-type }}
36+
ini-values: apc.enable_cli = 1
37+
coverage: pcov
38+
39+
- name: Get composer cache directory
40+
id: composer-cache
41+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
42+
43+
- name: Get date part for cache key
44+
id: key-date
45+
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
46+
47+
- name: Cache composer dependencies
48+
uses: actions/cache@v4
49+
with:
50+
path: ${{ steps.composer-cache.outputs.dir }}
51+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
52+
53+
- name: composer install
54+
run: |
55+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
56+
composer update --prefer-lowest --prefer-stable
57+
else
58+
composer update
59+
fi
60+
61+
- name: Setup problem matchers for PHPUnit
62+
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
63+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
64+
65+
- name: Run PHPUnit
66+
run: |
67+
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
68+
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi
69+
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
70+
vendor/bin/phpunit
71+
72+
cs-stan:
73+
name: Coding Standard & Static Analysis
74+
runs-on: ubuntu-22.04
75+
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- name: Setup PHP
80+
uses: shivammathur/setup-php@v2
81+
with:
82+
php-version: '8.1'
83+
extensions: mbstring, intl, apcu
84+
coverage: none
85+
86+
- name: Get composer cache directory
87+
id: composer-cache
88+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
89+
90+
- name: Get date part for cache key
91+
id: key-date
92+
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
93+
94+
- name: Cache composer dependencies
95+
uses: actions/cache@v4
96+
with:
97+
path: ${{ steps.composer-cache.outputs.dir }}
98+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
99+
100+
- name: composer install
101+
run: composer stan-setup
102+
103+
- name: Run PHP CodeSniffer
104+
run: composer cs-check
105+
106+
- name: Run psalm
107+
if: success() || failure()
108+
run: vendor/bin/psalm.phar --output-format=github
109+
110+
- name: Run phpstan
111+
if: success() || failure()
112+
run: composer stan

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0] - 2024-04-17
9+
10+
### Added
11+
12+
- First release for CakePHP 5.0
13+
14+
## [1.0] - 2024-04-17
15+
16+
### Added
17+
18+
- First release for CakePHP 4.4

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Contributing
2+
============
3+
4+
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to
5+
contribute new features, enhancements or bug fixes to the plugin, please read our
6+
[Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Cake Development Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# CakeDC Queue Monitor Plugin for CakePHP
2+
3+
## Versions and branches
4+
| CakePHP | CakeDC Queue Monitor Plugin | Tag | Notes |
5+
|:-------:|:--------------------------------------------------------------------------:|:------------:|:-------|
6+
| ^5.0 | [2.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/2.next-cake5) | 2.next-cake5 | stable |
7+
| ^4.4 | [1.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/1.next-cake4) | 1.next-cake4 | stable |
8+
9+
## Overview
10+
11+
The CakeDC Queue Monitor Plugin adds the ability to monitor jobs in queues that are handled by the
12+
[CakePHP Queue Plugin](https://github.com/cakephp/queue). This plugin checks the duration of work of
13+
individual Jobs and sends a notification when this time is exceeded by a configurable value.
14+
15+
## Requirements
16+
* CakePHP 4.4
17+
* PHP 8.1+
18+
19+
## Installation
20+
21+
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).
22+
23+
The recommended way to install composer package is:
24+
```
25+
composer require cakedc/queue-monitor
26+
```
27+
28+
## Configuration
29+
30+
Add QueueMonitorPlugin to your `Application::bootstrap`:
31+
```php
32+
use Cake\Http\BaseApplication;
33+
use CakeDC\QueueMonitor\QueueMonitorPlugin;
34+
35+
class Application extends BaseApplication
36+
{
37+
// ...
38+
39+
public function bootstrap(): void
40+
{
41+
parent::bootstrap();
42+
43+
$this->addPlugin(QueueMonitorPlugin::class);
44+
}
45+
46+
// ...
47+
}
48+
49+
```
50+
51+
Set up the QueueMonitor configuration in your `config/app_local.php`:
52+
```php
53+
// ...
54+
'QueueMonitor' => [
55+
// mailer config, the default is `default` mailer, you can ommit
56+
// this setting if you use default value
57+
'mailerConfig' => 'myCustomMailer',
58+
59+
// the default is 30 minutes, you can ommit this setting if you
60+
// use the default value
61+
'longJobInMinutes' => 45,
62+
63+
// the default is 30 days, you can ommit this setting if you
64+
// its advised to set this value correctly after queue usage analysis to avoid
65+
// high space usage in db
66+
'purgeLogsOlderThanDays' => 10,
67+
68+
// comma separated list of recipients of notification about long running queue jobs
69+
70+
],
71+
// ...
72+
```
73+
74+
Run the required migrations
75+
```shell
76+
bin/cake migrations migrate -p CakeDC/QueueMonitor
77+
```
78+
79+
For each queue configuration add `listener` setting
80+
```php
81+
// ...
82+
'Queue' => [
83+
'default' => [
84+
// ...
85+
'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class,
86+
// ...
87+
]
88+
],
89+
// ...
90+
```
91+
92+
## Notification command
93+
94+
To set up notifications when there are long running or possible stuck jobs please use command
95+
```shell
96+
bin/cake queue_monitor notify
97+
```
98+
99+
This command will send notification emails to recipients specified in `QueueMonitor.notificationRecipients`. Best is
100+
to use it as a cronjob
101+
102+
## Purge command
103+
104+
The logs table may grow overtime, to keep it slim you can use the purge command:
105+
```shell
106+
bin/cake queue_monitor purge
107+
```
108+
109+
This command will purge logs older than value specified in `QueueMonitor.purgeLogsOlderThanDays`, the value is in
110+
days, the default is 30 days. Best is to use it as a cronjob
111+
112+
## Important
113+
114+
Make sure your Job classes have a property value of maxAttempts because if it's missing, the log table can quickly
115+
grow to gigantic size in the event of an uncaught exception in Job, Job is re-queued indefinitely in such a case.

composer.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "cakedc/queue-monitor",
3+
"description": "CakeDC Queue Monitor plugin for CakePHP",
4+
"type": "cakephp-plugin",
5+
"license": "MIT",
6+
"keywords": [
7+
"cakephp",
8+
"queue",
9+
"queue monitoring",
10+
"queue monitor"
11+
],
12+
"homepage": "https://github.com/CakeDC/cakephp-queue-monitor",
13+
"authors": [
14+
{
15+
"name": "CakeDC",
16+
"homepage": "https://www.cakedc.com",
17+
"role": "Author"
18+
},
19+
{
20+
"name": "Others",
21+
"homepage": "https://github.com/CakeDC/cakephp-queue-monitor/graphs/contributors"
22+
}
23+
],
24+
"support": {
25+
"issues": "https://github.com/CakeDC/cakephp-queue-monitor/issues",
26+
"source": "https://github.com/CakeDC/cakephp-queue-monitor"
27+
},
28+
"require": {
29+
"php": ">=8.1",
30+
"cakephp/cakephp": "^4.4",
31+
"cakephp/queue": "^1.1",
32+
"ext-json": "*"
33+
},
34+
"require-dev": {
35+
"phpunit/phpunit": "^9.6",
36+
"cakephp/migrations": "^3.9",
37+
"cakephp/cakephp-codesniffer": "^4.5"
38+
},
39+
"autoload": {
40+
"psr-4": {
41+
"CakeDC\\QueueMonitor\\": "src/"
42+
}
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"CakeDC\\QueueMonitor\\Test\\": "tests/",
47+
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
48+
}
49+
},
50+
"scripts": {
51+
"analyse": [
52+
"@stan",
53+
"@psalm"
54+
],
55+
"check": [
56+
"@cs-check",
57+
"@test",
58+
"@analyse"
59+
],
60+
"cs-check": "phpcs -n -p ./src ./tests",
61+
"cs-fix": "phpcbf ./src ./tests",
62+
"test": "phpunit --stderr",
63+
"stan": "phpstan analyse src/",
64+
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
65+
"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",
66+
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon",
67+
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/",
68+
"rector": "rector process src/",
69+
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.11.2 && mv composer.backup composer.json",
70+
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
71+
},
72+
"config": {
73+
"allow-plugins": {
74+
"dealerdirect/phpcodesniffer-composer-installer": true
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)