Skip to content

Commit c79a035

Browse files
committed
initial commit of CakePHP 5.0 version
1 parent f3d0ee4 commit c79a035

27 files changed

+1633
-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

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 2.next-cake5
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
testsuite:
16+
uses: cakephp/.github/.github/workflows/[email protected]
17+
secrets: inherit
18+
19+
cs-stan:
20+
uses: cakephp/.github/.github/workflows/[email protected]
21+
secrets: inherit

.phive/phars.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpstan" version="1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
4+
<phar name="psalm" version="5.23.1" installed="5.23.1" location="./tools/psalm" copy="false"/>
5+
</phive>

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 5.0
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

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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": "^5.0.1",
31+
"cakephp/queue": "^2.0",
32+
"ext-json": "*"
33+
},
34+
"require-dev": {
35+
"phpunit/phpunit": "^10.1.0",
36+
"cakephp/migrations": "^4.0.0",
37+
"cakephp/cakephp-codesniffer": "^5.1"
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+
"check": [
52+
"@cs-check",
53+
"@test"
54+
],
55+
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
56+
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
57+
"phpstan": "tools/phpstan analyse",
58+
"psalm": "tools/psalm --show-info=false",
59+
"stan": [
60+
"@phpstan",
61+
"@psalm"
62+
],
63+
"stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
64+
"stan-baseline": "phpstan.phar --generate-baseline",
65+
"stan-setup": "phive install",
66+
"test": "phpunit",
67+
"test-coverage": "phpunit --coverage-clover=clover.xml"
68+
},
69+
"config": {
70+
"allow-plugins": {
71+
"dealerdirect/phpcodesniffer-composer-installer": true
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)