Skip to content

Commit

Permalink
ListCommand: Fix numeric job ids in case option --next is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Dec 11, 2023
1 parent 2f0d896 commit 284a012
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `ManagedScheduler`
- acquired job locks are scoped just to their id - changing run frequency or job name will not make process loose
the lock

### Fixed

- `ListCommand`
- Fix numeric job ids in case option --next is used
14 changes: 12 additions & 2 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
use function abs;
use function array_splice;
use function floor;
use function max;
use function mb_strlen;
Expand Down Expand Up @@ -173,7 +172,18 @@ private function sortJobs(array $jobs, $next): array
});

if ($next !== true) {
array_splice($jobs, $next);
$slicedJobs = [];
$count = 0;
foreach ($jobs as $key => $value) {
if ($count >= $next) {
break;
}

$slicedJobs[$key] = $value;
$count++;
}

$jobs = $slicedJobs;
}
} else {
/** @infection-ignore-all */
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Command/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ public function testNext(): void

self::assertSame(
<<<'MSG'
* * * * * / 1 [0] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 second
* * * * * [1] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds
* * * * * [2] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds
* * * * * / 1 [5] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 second
* * * * * [4] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds
* * * * * [6] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()...... Next Due: 59 seconds
2 * * * * [3] Tests\Orisai\Scheduler\Doubles\CallbackList::job1()........ Next Due: 1 minute

MSG,
Expand Down

0 comments on commit 284a012

Please sign in to comment.