Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BatchProcess): show interrupt message only once #120

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* feat: add `BatchProcess` and related classes
* feat(`BatchProcess`): add `SimpleBatchProcess`, simplify wiring, add
process-file feature
* fix(`BatchProcess`): show interrupt message only once

# 0.13.0

Expand Down
10 changes: 8 additions & 2 deletions packages/rekapager-core/src/Batch/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ public function __construct(
$this->logger = $logger ?? new NullLogger();
}

final public function stop(): void
final public function stop(): bool
{
$this->stopFlag = true;
if ($this->stopFlag === false) {
$this->stopFlag = true;

return true;
}

return false;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/rekapager-symfony-bridge/src/BatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Rekalogika\Rekapager\Symfony;

use Doctrine\DBAL\Driver\PgSQL\Exception\UnexpectedValue;
use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException;
use Rekalogika\Contracts\Rekapager\Exception\LogicException;
use Rekalogika\Contracts\Rekapager\Exception\UnexpectedValueException;
Expand Down Expand Up @@ -103,7 +102,7 @@ final protected function execute(InputInterface $input, OutputInterface $output)
if ($progressFile !== null && file_exists($progressFile) && $resume === null) {
$resume = file_get_contents($progressFile);

if (!is_string($resume)) {
if (!\is_string($resume)) {
throw new UnexpectedValueException(sprintf('Invalid resume data in progress file "%s"', $progressFile));
}
}
Expand Down Expand Up @@ -143,9 +142,11 @@ public function handleSignal(int $signal, int|false $previousExitCode = 0): int|
return false;
}

$this->io?->warning('Interrupt received, stopping batch processing');
$result = (bool) $this->batchProcess?->stop();

$this->batchProcess?->stop();
if ($result === true) {
$this->io?->warning('Interrupt received, stopping batch processing');
}

return false;
}
Expand Down