Skip to content

Commit 1320cf6

Browse files
committed
process review feedback
1 parent 106562b commit 1320cf6

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed

src/Command/SubprocessJobRunnerCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/)
1313
* @link https://cakephp.org CakePHP(tm) Project
14-
* @since 0.1.0
14+
* @since 2.2.0
1515
* @license https://opensource.org/licenses/MIT MIT License
1616
*/
1717
namespace Cake\Queue\Command;
@@ -28,6 +28,7 @@
2828
use Enqueue\Null\NullMessage;
2929
use Interop\Queue\Message as QueueMessage;
3030
use Interop\Queue\Processor as InteropProcessor;
31+
use JsonException;
3132
use Psr\Log\LoggerInterface;
3233
use Psr\Log\NullLogger;
3334
use RuntimeException;
@@ -54,7 +55,7 @@ public function __construct(
5455
*/
5556
public static function defaultName(): string
5657
{
57-
return 'queue subprocess-runner';
58+
return 'queue subprocess_runner';
5859
}
5960

6061
/**
@@ -68,7 +69,7 @@ public function execute(Arguments $args, ConsoleIo $io): int
6869
{
6970
$input = $this->readInput($io);
7071

71-
if (empty($input)) {
72+
if ($input === '') {
7273
$this->outputResult($io, [
7374
'success' => false,
7475
'error' => 'No input received',
@@ -77,11 +78,12 @@ public function execute(Arguments $args, ConsoleIo $io): int
7778
return self::CODE_ERROR;
7879
}
7980

80-
$data = json_decode($input, true);
81-
if (json_last_error() !== JSON_ERROR_NONE) {
81+
try {
82+
$data = json_decode($input, true, 512, JSON_THROW_ON_ERROR);
83+
} catch (JsonException $jsonException) {
8284
$this->outputResult($io, [
8385
'success' => false,
84-
'error' => 'Invalid JSON input: ' . json_last_error_msg(),
86+
'error' => 'Invalid JSON input: ' . $jsonException->getMessage(),
8587
]);
8688

8789
return self::CODE_ERROR;

src/Queue/SubprocessProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/)
1313
* @link https://cakephp.org CakePHP(tm) Project
14-
* @since 0.1.0
14+
* @since 2.2.0
1515
* @license https://opensource.org/licenses/MIT MIT License
1616
*/
1717
namespace Cake\Queue\Queue;
@@ -30,7 +30,7 @@
3030
* to be reloaded without restarting the worker.
3131
*
3232
* Configuration options:
33-
* - `command`: Full command to execute (default: 'php bin/cake.php queue subprocess-runner')
33+
* - `command`: Full command to execute (default: 'php bin/cake.php queue subprocess_runner')
3434
* - `timeout`: Maximum execution time in seconds (default: 300)
3535
* - `maxOutputSize`: Maximum output size in bytes (default: 1048576 = 1MB)
3636
*
@@ -39,7 +39,7 @@
3939
* 'Queue' => [
4040
* 'default' => [
4141
* 'subprocess' => [
42-
* 'command' => 'php bin/cake.php queue subprocess-runner',
42+
* 'command' => 'php bin/cake.php queue subprocess_runner',
4343
* 'timeout' => 60,
4444
* 'maxOutputSize' => 2097152, // 2MB
4545
* ],
@@ -134,7 +134,7 @@ protected function prepareJobData(QueueMessage $message): array
134134
*/
135135
protected function executeInSubprocess(array $jobData): array
136136
{
137-
$command = $this->config['command'] ?? 'php bin/cake.php queue subprocess-runner';
137+
$command = $this->config['command'] ?? 'php bin/cake.php queue subprocess_runner';
138138
$timeout = $this->config['timeout'] ?? 300;
139139

140140
$descriptors = [

src/QueuePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function console(CommandCollection $commands): CommandCollection
8181
return $commands
8282
->add('queue worker', WorkerCommand::class)
8383
->add('worker', WorkerCommand::class)
84-
->add('queue subprocess-runner', SubprocessJobRunnerCommand::class)
84+
->add('queue subprocess_runner', SubprocessJobRunnerCommand::class)
8585
->add('queue requeue', RequeueCommand::class)
8686
->add('queue purge_failed', PurgeFailedCommand::class);
8787
}

tests/TestCase/Command/SubprocessJobRunnerCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function testLogsRedirectedToStderr(): void
273273
'logger' => 'debug',
274274
];
275275

276-
$command = 'php ' . ROOT . 'bin/cake.php queue subprocess-runner';
276+
$command = 'php ' . ROOT . 'bin/cake.php queue subprocess_runner';
277277

278278
$descriptors = [
279279
0 => ['pipe', 'r'],
@@ -326,7 +326,7 @@ public function testLogsRedirectedToStderr(): void
326326
*/
327327
public function testDefaultName(): void
328328
{
329-
$this->assertSame('queue subprocess-runner', SubprocessJobRunnerCommand::defaultName());
329+
$this->assertSame('queue subprocess_runner', SubprocessJobRunnerCommand::defaultName());
330330
}
331331

332332
/**

tests/TestCase/Command/WorkerCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function testQueueProcessesJobWithSubprocessFlag()
450450
'url' => 'file:///' . TMP . DS . 'queue',
451451
'receiveTimeout' => 100,
452452
'subprocess' => [
453-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
453+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
454454
],
455455
];
456456
Configure::write('Queue', ['default' => $config]);
@@ -484,7 +484,7 @@ public function testQueueProcessesJobWithSubprocessConfig()
484484
'subprocess' => [
485485
'enabled' => true,
486486
'timeout' => 30,
487-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
487+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
488488
],
489489
];
490490
Configure::write('Queue', ['default' => $config]);

tests/TestCase/Queue/SubprocessProcessorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function testRealSubprocessExecutionAck(): void
225225

226226
$logger = new ArrayLog();
227227
$config = [
228-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
228+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
229229
];
230230
$processor = new SubprocessProcessor($logger, $config);
231231

@@ -253,7 +253,7 @@ public function testRealSubprocessExecutionReject(): void
253253

254254
$logger = new ArrayLog();
255255
$config = [
256-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
256+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
257257
];
258258
$processor = new SubprocessProcessor($logger, $config);
259259

@@ -281,7 +281,7 @@ public function testRealSubprocessExecutionWithException(): void
281281

282282
$logger = new ArrayLog();
283283
$config = [
284-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
284+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
285285
];
286286
$processor = new SubprocessProcessor($logger, $config);
287287

@@ -309,7 +309,7 @@ public function testSubprocessTimeout(): void
309309

310310
$logger = new ArrayLog();
311311
$config = [
312-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
312+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
313313
'timeout' => 1,
314314
];
315315
$processor = new SubprocessProcessor($logger, $config);
@@ -344,7 +344,7 @@ public function testSubprocessWithInvalidCommand(): void
344344

345345
$logger = new ArrayLog();
346346
$config = [
347-
'command' => '/nonexistent/binary queue subprocess-runner',
347+
'command' => '/nonexistent/binary queue subprocess_runner',
348348
];
349349
$processor = new SubprocessProcessor($logger, $config);
350350

@@ -445,7 +445,7 @@ public function testProcessJobInSubprocess(): void
445445

446446
$logger = new ArrayLog();
447447
$config = [
448-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
448+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
449449
];
450450
$processor = new SubprocessProcessor($logger, $config);
451451

@@ -468,7 +468,7 @@ public function testProcessJobInSubprocessReject(): void
468468

469469
$logger = new ArrayLog();
470470
$config = [
471-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
471+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
472472
];
473473
$processor = new SubprocessProcessor($logger, $config);
474474

@@ -491,7 +491,7 @@ public function testProcessJobInSubprocessWithException(): void
491491

492492
$logger = new ArrayLog();
493493
$config = [
494-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
494+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
495495
];
496496
$processor = new SubprocessProcessor($logger, $config);
497497

@@ -574,7 +574,7 @@ public function testSubprocessWithNormalOutputSize(): void
574574

575575
$logger = new ArrayLog();
576576
$config = [
577-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
577+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
578578
'maxOutputSize' => 1048576, // 1MB - normal size
579579
'timeout' => 30,
580580
];

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
'subprocess' => [
9999
'enabled' => false,
100100
'timeout' => 30,
101-
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess-runner',
101+
'command' => 'php ' . ROOT . 'bin/cake.php queue subprocess_runner',
102102
],
103103
],
104104
]);

tests/test_app/src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function bootstrap(): void
3737
'subprocess' => [
3838
'enabled' => false,
3939
'timeout' => 30,
40-
'command' => 'php ' . dirname(__DIR__, 2) . '/bin/cake.php queue subprocess-runner',
40+
'command' => 'php ' . dirname(__DIR__, 2) . '/bin/cake.php queue subprocess_runner',
4141
],
4242
],
4343
]);

0 commit comments

Comments
 (0)