Skip to content

Commit 058d46e

Browse files
authored
Add support for multiple queues
2 parents 73dc4ea + 6735a52 commit 058d46e

12 files changed

Lines changed: 747 additions & 81 deletions

File tree

.github/workflows/tests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
tests:
11+
name: PHPUnit (PHP ${{ matrix.php }})
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php: ['8.2', '8.3', '8.4']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
coverage: none
28+
29+
- name: Validate composer.json
30+
run: composer validate
31+
32+
- name: Get Composer cache directory
33+
id: composer-cache
34+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
35+
36+
- name: Cache Composer dependencies
37+
uses: actions/cache@v4
38+
with:
39+
path: ${{ steps.composer-cache.outputs.dir }}
40+
key: composer-${{ matrix.php }}-${{ hashFiles('composer.json') }}
41+
restore-keys: composer-${{ matrix.php }}-
42+
43+
- name: Install dependencies
44+
run: composer install --prefer-dist --no-interaction --no-progress
45+
46+
- name: Run tests
47+
run: composer test
48+
49+
php74-compat:
50+
name: PHP 7.4 compatibility
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
57+
- name: Setup PHP
58+
uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: '7.4'
61+
coverage: none
62+
63+
- name: Lint sources against PHP 7.4
64+
run: find src -name '*.php' -print0 | xargs -0 -n1 -P4 php -l

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@
1111
"php": ">=7.4",
1212
"laravel/framework": ">=7.0.0"
1313
},
14+
"require-dev": {
15+
"orchestra/testbench": "10.0"
16+
},
1417
"autoload": {
1518
"psr-4": {
1619
"PleskExtLaravel\\": "src/"
1720
}
1821
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"PleskExtLaravel\\Tests\\": "tests/"
25+
}
26+
},
1927
"extra": {
2028
"component": "package",
2129
"laravel": {
@@ -25,10 +33,10 @@
2533
}
2634
},
2735
"config": {
28-
"platform": {
29-
"php": "7.4.0"
30-
},
3136
"sort-packages": true
3237
},
38+
"scripts": {
39+
"test": "phpunit"
40+
},
3341
"prefer-stable": true
3442
}

config/plesk-ext-laravel.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheDirectory=".phpunit.cache"
7+
failOnWarning="true">
8+
<testsuites>
9+
<testsuite name="Package">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<source>
14+
<include>
15+
<directory>src</directory>
16+
</include>
17+
</source>
18+
</phpunit>

src/Console/Commands/ConfigSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PleskExtLaravel\Console\Commands;
44

55
use Illuminate\Console\Command;
6+
use PleskExtLaravel\PleskEnv;
67

78
class ConfigSource extends Command
89
{
@@ -12,6 +13,6 @@ class ConfigSource extends Command
1213

1314
public function handle()
1415
{
15-
$this->line(config('plesk-ext-laravel.config-source'));
16+
$this->line(PleskEnv::configSource());
1617
}
1718
}

src/Console/Commands/ListEnv.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,79 @@
33
namespace PleskExtLaravel\Console\Commands;
44

55
use Illuminate\Console\Command;
6+
use PleskExtLaravel\PleskEnv;
67

78
class ListEnv extends Command
89
{
9-
private const CONFIG_PARAMETERS_MAP = [
10-
'plesk-ext-laravel.queue-worker.enabled' => 'PLESK_EXT_LARAVEL_QUEUE_WORKER_ENABLED',
11-
'plesk-ext-laravel.queue-worker.params.stop-when-empty' => 'PLESK_EXT_LARAVEL_QUEUE_WORKER_STOP_WHEN_EMPTY',
12-
'plesk-ext-laravel.queue-worker.params.timeout' => 'PLESK_EXT_LARAVEL_QUEUE_WORKER_TIMEOUT',
13-
'plesk-ext-laravel.queue-worker.params.max-jobs' => 'PLESK_EXT_LARAVEL_QUEUE_WORKER_MAX_JOBS',
14-
'plesk-ext-laravel.queue-worker.params.max-time' => 'PLESK_EXT_LARAVEL_QUEUE_WORKER_MAX_TIME',
15-
];
16-
1710
protected $signature = 'plesk-ext-laravel:list-env';
1811

19-
protected $description = 'Display environment variables setted for Plesk Laravel Toolkit extension integration.';
12+
protected $description = 'Display environment variables set for Plesk Laravel Toolkit extension integration.';
2013

2114
public function handle()
15+
{
16+
$parameters = PleskEnv::isMultiQueue()
17+
? $this->multiQueueParameters()
18+
: $this->legacyParameters();
19+
20+
$this->table(['Parameter', 'Value'], $parameters);
21+
}
22+
23+
/**
24+
* Legacy single-worker output, kept identical to previous versions.
25+
*
26+
* @return array<int, array{parameter: string, value: string}>
27+
*/
28+
private function legacyParameters(): array
2229
{
2330
$parameters = [];
24-
foreach (self::CONFIG_PARAMETERS_MAP as $key => $name) {
25-
$value = config($key);
31+
foreach (PleskEnv::legacyParameterNames() as $name) {
32+
$value = PleskEnv::get($name);
2633

27-
if (is_bool($value)) {
28-
$value = $value ? 'true' : 'false';
34+
if ($value === null) {
35+
// The legacy "enabled" flag defaulted to false, so it was shown
36+
// as "false" when unset; other params were shown empty.
37+
$value = $name === PleskEnv::LEGACY_ENABLED ? 'false' : '';
2938
}
3039

3140
$parameters[] = [
3241
'parameter' => $name,
3342
'value' => $value,
3443
];
3544
}
36-
$this->table(['Parameter', 'Value'], $parameters);
45+
46+
return $parameters;
47+
}
48+
49+
/**
50+
* Multi-queue output: the queue list plus the per-queue variables of every
51+
* listed queue.
52+
*
53+
* @return array<int, array{parameter: string, value: string}>
54+
*/
55+
private function multiQueueParameters(): array
56+
{
57+
$parameters = [[
58+
'parameter' => PleskEnv::LIST_VAR,
59+
'value' => PleskEnv::get(PleskEnv::LIST_VAR) ?? '',
60+
]];
61+
62+
foreach (PleskEnv::queues() as $queue) {
63+
foreach (PleskEnv::queueSuffixes() as $suffix) {
64+
$name = PleskEnv::key($queue, $suffix);
65+
66+
// COUNT falls back to 1 when unset (same as the scheduler),
67+
// so the displayed value matches what actually runs.
68+
$value = $suffix === PleskEnv::SUFFIX_COUNT
69+
? (string) PleskEnv::count($queue)
70+
: PleskEnv::get($name) ?? '';
71+
72+
$parameters[] = [
73+
'parameter' => $name,
74+
'value' => $value,
75+
];
76+
}
77+
}
78+
79+
return $parameters;
3780
}
3881
}

0 commit comments

Comments
 (0)