Skip to content

Commit

Permalink
fix(BatchProcess): show interrupt message only once (#120)
Browse files Browse the repository at this point in the history
* fix(`BatchProcess`): show interrupt message only once

* fix
  • Loading branch information
priyadi authored Jul 15, 2024
1 parent d85ccaa commit bb2205c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
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

0 comments on commit bb2205c

Please sign in to comment.