Skip to content

Commit 84ac7f2

Browse files
committed
Update package info, dependencies, keywords, CLI entry point, BabelQueue, URN docs, PHPUnit config, remove adapters, add interfaces, EnvelopeCodec, Handler classes, Producer, Transport, Worker resilience, tests, fixtures, PdoMysql, Redis, ReceivedMessage, CallableHandler, HandlerMap, ArrayTransport, InMemoryRedis, RecordingHandler, SampleJob, ThrowingHandler, Transport tests
1 parent 90f7c5b commit 84ac7f2

74 files changed

Lines changed: 5598 additions & 903 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master, "*.x"]
6+
pull_request:
7+
branches: [main, master, "*.x"]
8+
9+
jobs:
10+
validate:
11+
name: composer validate
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: "8.2"
18+
coverage: none
19+
tools: composer:v2
20+
- run: composer validate --strict --no-check-publish
21+
22+
cs:
23+
name: PHP-CS-Fixer
24+
runs-on: ubuntu-latest
25+
needs: validate
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: "8.2"
31+
extensions: sockets, mbstring
32+
coverage: none
33+
tools: composer:v2
34+
- name: Install dependencies
35+
run: composer install --prefer-dist --no-progress --no-interaction
36+
- name: Check coding standards
37+
run: composer cs-check
38+
39+
stan:
40+
name: PHPStan
41+
runs-on: ubuntu-latest
42+
needs: validate
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: "8.2"
48+
extensions: sockets, mbstring
49+
coverage: none
50+
tools: composer:v2
51+
- name: Install dependencies
52+
run: composer install --prefer-dist --no-progress --no-interaction
53+
- name: Run PHPStan
54+
run: composer stan
55+
56+
tests:
57+
name: PHPUnit (PHP ${{ matrix.php }}, ${{ matrix.deps }})
58+
runs-on: ubuntu-latest
59+
needs: validate
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
php: ["8.2", "8.3", "8.4"]
64+
deps: ["highest"]
65+
include:
66+
- php: "8.2"
67+
deps: "lowest"
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Set up PHP ${{ matrix.php }}
72+
uses: shivammathur/setup-php@v2
73+
with:
74+
php-version: ${{ matrix.php }}
75+
extensions: pdo_sqlite, pcntl, sockets, mbstring
76+
coverage: none
77+
tools: composer:v2
78+
79+
- name: Get composer cache directory
80+
id: composer-cache
81+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
82+
83+
- name: Cache composer dependencies
84+
uses: actions/cache@v4
85+
with:
86+
path: ${{ steps.composer-cache.outputs.dir }}
87+
key: composer-${{ matrix.php }}-${{ matrix.deps }}-${{ hashFiles('**/composer.json') }}
88+
restore-keys: composer-${{ matrix.php }}-${{ matrix.deps }}-
89+
90+
- name: Install highest dependencies
91+
if: matrix.deps == 'highest'
92+
run: composer update --prefer-dist --no-progress --no-interaction
93+
94+
- name: Install lowest dependencies
95+
if: matrix.deps == 'lowest'
96+
run: composer update --prefer-dist --no-progress --no-interaction --prefer-lowest --prefer-stable
97+
98+
- name: Run unit tests
99+
run: vendor/bin/phpunit --exclude-group integration
100+
101+
integration:
102+
name: Integration (Redis, RabbitMQ, MySQL)
103+
runs-on: ubuntu-latest
104+
needs: validate
105+
services:
106+
redis:
107+
image: redis:7
108+
ports:
109+
- 6379:6379
110+
options: >-
111+
--health-cmd "redis-cli ping"
112+
--health-interval 10s
113+
--health-timeout 5s
114+
--health-retries 5
115+
rabbitmq:
116+
image: rabbitmq:3.13-alpine
117+
env:
118+
RABBITMQ_DEFAULT_USER: app
119+
RABBITMQ_DEFAULT_PASS: app
120+
ports:
121+
- 5672:5672
122+
options: >-
123+
--health-cmd "rabbitmq-diagnostics -q ping"
124+
--health-interval 10s
125+
--health-timeout 5s
126+
--health-retries 10
127+
mysql:
128+
image: mysql:8.0
129+
env:
130+
MYSQL_ROOT_PASSWORD: root
131+
MYSQL_DATABASE: queue_test
132+
ports:
133+
- 3306:3306
134+
options: >-
135+
--health-cmd "mysqladmin ping -h 127.0.0.1 -proot"
136+
--health-interval 10s
137+
--health-timeout 5s
138+
--health-retries 10
139+
steps:
140+
- uses: actions/checkout@v4
141+
142+
- name: Set up PHP
143+
uses: shivammathur/setup-php@v2
144+
with:
145+
php-version: "8.3"
146+
extensions: pdo_mysql, sockets, pcntl, bcmath, mbstring
147+
coverage: none
148+
tools: composer:v2
149+
150+
- name: Install dependencies
151+
run: composer install --prefer-dist --no-progress --no-interaction
152+
153+
- name: Run integration tests
154+
env:
155+
QUEUE_TEST_REDIS_DSN: "tcp://127.0.0.1:6379"
156+
QUEUE_TEST_AMQP_HOST: "127.0.0.1"
157+
QUEUE_TEST_AMQP_PORT: "5672"
158+
QUEUE_TEST_AMQP_USER: "app"
159+
QUEUE_TEST_AMQP_PASS: "app"
160+
QUEUE_TEST_MYSQL_DSN: "mysql:host=127.0.0.1;port=3306;dbname=queue_test"
161+
QUEUE_TEST_MYSQL_USER: "root"
162+
QUEUE_TEST_MYSQL_PASS: "root"
163+
run: vendor/bin/phpunit --group integration
164+
165+
coverage:
166+
name: Coverage
167+
runs-on: ubuntu-latest
168+
needs: tests
169+
steps:
170+
- uses: actions/checkout@v4
171+
172+
- name: Set up PHP
173+
uses: shivammathur/setup-php@v2
174+
with:
175+
php-version: "8.3"
176+
extensions: pdo_sqlite, pcntl, sockets, mbstring
177+
coverage: pcov
178+
tools: composer:v2
179+
180+
- name: Install dependencies
181+
run: composer install --prefer-dist --no-progress --no-interaction
182+
183+
- name: Run unit tests with coverage
184+
run: vendor/bin/phpunit --exclude-group integration --coverage-clover=coverage.xml
185+
186+
- name: Upload coverage artifact
187+
uses: actions/upload-artifact@v4
188+
with:
189+
name: coverage-clover
190+
path: coverage.xml
191+
retention-days: 14
192+
193+
- name: Upload coverage to Codecov
194+
uses: codecov/codecov-action@v5
195+
with:
196+
files: ./coverage.xml
197+
flags: phpunit
198+
fail_ci_if_error: false

.gitignore

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
/.idea/
2-
/.vs/
3-
/.vscode/
4-
/vendor/
5-
/composer.lock
6-
/.phpunit.result.cache
7-
/nbproject/private/
8-
/*.log
1+
/.idea/
2+
/.vs/
3+
/.vscode/
4+
/vendor/
5+
/build/
6+
/composer.lock
7+
/coverage.xml
8+
/.phpunit.cache/
9+
/.phpunit.result.cache
10+
/.php-cs-fixer.cache
11+
/nbproject/private/
12+
/*.log

.php-cs-fixer.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in([__DIR__ . '/src', __DIR__ . '/tests'])
7+
->name('*.php');
8+
9+
return (new PhpCsFixer\Config())
10+
->setRiskyAllowed(true)
11+
->setRules([
12+
'@PSR12' => true,
13+
'@PHP82Migration' => true,
14+
'declare_strict_types' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
17+
'no_unused_imports' => true,
18+
'single_quote' => true,
19+
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']],
20+
'native_function_invocation' => false,
21+
])
22+
->setFinder($finder);

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Changelog
2+
3+
All notable changes to `initphp/queue` are documented here. The format is based
4+
on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project
5+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased] — 2.0
8+
9+
### Changed (breaking)
10+
11+
`2.0` is a full rewrite. InitPHP Queue is now **the framework-less BabelQueue
12+
runtime for plain PHP**: it owns the consumer/worker loop, retries and
13+
dead-letter routing that [`babelqueue/php-sdk`](https://github.com/BabelQueue/php-sdk)
14+
deliberately leaves to the framework, while reusing the SDK's canonical
15+
`{ job, trace_id, data, meta, attempts }` envelope so messages interoperate with
16+
Go, Python, Node and any other BabelQueue SDK.
17+
18+
- Requires PHP `^8.2` (was `>=7.4`) and depends on `babelqueue/php-sdk ^1.0`.
19+
- Messages are routed by **URN** (`urn:babel:<context>:<event>`) to mapped
20+
handlers, instead of serialising the producing PHP class name into the
21+
payload. This removes the PHP-only `new $classFromPayload()` coupling.
22+
- The abstract `Job` base class, `JobInterface`, `AdapterInterface`,
23+
`PDOAdapter` and `RabbitMQAdapter` are removed. See [UPGRADE-2.0.md](UPGRADE-2.0.md).
24+
25+
### Fixed
26+
27+
Bugs from `1.x` that no longer exist in the new design:
28+
29+
- The PDO worker never instantiated jobs (`$jobClass($this)` called a function
30+
instead of `new $jobClass(...)`), so the database adapter never ran any job.
31+
- `RabbitMQAdapter::close()` dereferenced a wrong (`_failed`) array key and threw.
32+
- `Job::push()` reported success even when the adapter's `push()` returned false.
33+
- The PDO consumer used a non-atomic `SELECT … status = 0` then `UPDATE`,
34+
letting two workers claim the same job, and busy-looped with no back-off.
35+
- `nack()` moved rows to the failed table via a column-position-dependent
36+
`INSERT … SELECT *`.
37+
38+
### Added
39+
40+
- `Worker` consumer loop with max-attempts, exponential back-off, max-jobs /
41+
max-runtime / memory limits and graceful `SIGINT`/`SIGTERM` shutdown.
42+
- URN → handler routing (`HandlerMap`, `Dispatcher`) with the four canonical
43+
unknown-URN strategies (`fail` / `delete` / `release` / `dead_letter`).
44+
- Consume-side transports for **PDO** (database), **Redis** (`BLMOVE`/`LREM`)
45+
and **RabbitMQ** (AMQP), each paired with the SDK's publish side.
46+
- A thin `Producer` facade over `EnvelopeCodec` + a `Transport`.
47+
- A `bin/queue` CLI worker entry point.

0 commit comments

Comments
 (0)