Skip to content

Commit 6eddc51

Browse files
author
Oliver Stark
committed
Prepare 3.1 release
1 parent 22b6d09 commit 6eddc51

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.1.0] - 2022-09-22
6+
7+
> {note} Upgrading is highly recommended. The previous version did not limit concurrency of queue runners. `ASYNC_QUEUE_CONCURRENCY` defaults to `1` now.
8+
9+
- Fixed RateLimiter
10+
- Added tests for RateLimiter / concurrency
11+
- Concurrency of queue runners defaults to `1` now
12+
13+
514
## [3.0.0] - 2022-05-12
615
- Craft 4 support
716
- PHP 8 syntax

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PHP_BINARY="/usr/local/Cellar/php71/7.1.0_11/bin/php"
5555
```
5656

5757

58-
By default `2` background processes handle the queue. With the `ASYNC_QUEUE_CONCURRENCY` ENV var you can modify this behaviour.
58+
By default `1` background process handles the queue. With the `ASYNC_QUEUE_CONCURRENCY` ENV var you can modify this behaviour.
5959
```
6060
# No concurrency
6161
ASYNC_QUEUE_CONCURRENCY=1

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
"require": {
2424
"php": "^8.0",
2525
"craftcms/cms": "^4.0.0",
26-
"symfony/process": "^5.0",
27-
"treeware/plant": "^0.1.0"
26+
"symfony/process": "^5.0"
2827
},
2928
"autoload": {
3029
"psr-4": {
3130
"ostark\\AsyncQueue\\": "src/"
3231
}
3332
},
3433
"extra": {
35-
"treeware": {},
3634
"name": "AsyncQueue",
3735
"handle": "async-queue",
3836
"hasCpSettings": false,
@@ -51,8 +49,7 @@
5149
"config": {
5250
"allow-plugins": {
5351
"yiisoft/yii2-composer": true,
54-
"craftcms/plugin-installer": true,
55-
"treeware/plant": true
52+
"craftcms/plugin-installer": true
5653
}
5754
},
5855
"prefer-stable": true,

src/Handlers/BackgroundQueueHandler.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,28 @@ public function __construct(Plugin $plugin)
2626

2727
public function __invoke(PushEvent $event): void
2828
{
29+
2930
$context = ($event->job instanceof JobInterface)
3031
? $event->job->getDescription()
3132
: 'Not instanceof craft\queue\JobInterface';
3233

3334
// Run queue in the background
3435
if ($this->plugin->getRateLimiter()->canIUse($context)) {
36+
3537
try {
36-
$this->plugin->getProcess()->start();
38+
$process = $this->plugin->getProcess()->start();
3739
$this->plugin->getRateLimiter()->increment();
3840
$handled = true;
3941

42+
$process->wait();
43+
4044
} catch (PhpExecutableNotFound) {
41-
Craft::debug(
45+
Craft::error(
4246
'QueueHandler::startBackgroundProcess() (PhpExecutableNotFound)',
4347
'async-queue'
4448
);
4549
} catch (RuntimeException | LogicException $e) {
46-
Craft::debug(
50+
Craft::error(
4751
Craft::t(
4852
'async-queue',
4953
'QueueHandler::startBackgroundProcess() (Job status: {status}. Exit code: {code})', [
@@ -68,7 +72,7 @@ protected function logPushEvent(PushEvent $event, bool $handled = false): void
6872
}
6973

7074
if ($event->job instanceof BaseJob) {
71-
Craft::debug(
75+
Craft::info(
7276
Craft::t(
7377
'async-queue',
7478
'New PushEvent for {job} job - ({handled})', [

src/QueueCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class QueueCommand extends Component
99
{
1010
public const DEFAULT_SCRIPT = "craft";
1111

12-
public const DEFAULT_ARGS = "queue/run";
12+
public const DEFAULT_ARGS = "queue/run -v";
1313

1414
public const EVENT_PREPARE_COMMAND = 'prepareCommand';
1515

@@ -68,7 +68,8 @@ protected function decorate(string $commandLine): string
6868
}
6969

7070
// default decoration
71-
return "nice -n 15 {$commandLine}"; // > /tmp/null.txt 2>&1 &
71+
return "nice -n 15 {$commandLine} > /dev/null 2>&1 &";
72+
7273
}
7374

7475
}

src/Settings.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,9 @@
44

55
class Settings extends Model
66
{
7-
// Public Properties
8-
// =========================================================================
7+
public int $concurrency;
98

10-
/**
11-
* @var integer
12-
*/
13-
public $concurrency;
14-
15-
/**
16-
* @var integer
17-
*/
18-
public $poolLifetime;
19-
20-
/**
21-
* @var bool
22-
*/
23-
public $enabled = true;
9+
public bool $enabled = true;
2410

2511

2612
/**
@@ -29,8 +15,7 @@ class Settings extends Model
2915
public function __construct(array $config = [])
3016
{
3117
$config = array_merge([
32-
'concurrency' => (int)$this->env('ASYNC_QUEUE_CONCURRENCY', 2),
33-
'poolLifetime' => (int)$this->env('ASYNC_QUEUE_POOL_LIFETIME', 3600),
18+
'concurrency' => (int) $this->env('ASYNC_QUEUE_CONCURRENCY', 1),
3419
'enabled' => ($this->env('DISABLE_ASYNC_QUEUE', '0') == '1') ? false : true
3520
], $config);
3621

src/TestUtility/TestJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestJob extends BaseJob
1313
*/
1414
public function execute($queue): void
1515
{
16-
sleep(10);
16+
sleep(3);
1717
}
1818

1919

tests/BackgroundProcessRunTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function test_start_default_dummy_script_success(): void
3232

3333
$process->wait();
3434

35+
// give it some time to write the test file
36+
usleep(150000);
37+
3538
$this->assertEquals(0, $process->getExitCode());
3639
$this->assertTrue($process->isSuccessful());
3740
$this->assertEquals(\Symfony\Component\Process\Process::STATUS_TERMINATED, $process->getStatus());
@@ -53,6 +56,8 @@ public function test_process_does_not_block(): void
5356
$command = new \ostark\AsyncQueue\QueueCommand('craft.php', '--sleep');
5457
$bgProcess = new BackgroundProcess($command);
5558
$process = $bgProcess->start();
59+
60+
// give it some time to write the test file
5661
usleep(150000);
5762

5863
$this->assertFileExists(TEST_FILE);
@@ -61,5 +66,4 @@ public function test_process_does_not_block(): void
6166
$this->assertGreaterThanOrEqual($content['timestamp'], time());
6267

6368
}
64-
6569
}

0 commit comments

Comments
 (0)