Skip to content

Commit cb5dd3f

Browse files
authored
Fix failover handling of chunked api commands (#1295)
fixes #1292
2 parents f88b644 + f2da482 commit cb5dd3f

18 files changed

+470
-69
lines changed

application/forms/Command/Object/AcknowledgeProblemForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use ipl\Web\FormDecorator\IcingaFormDecorator;
2121
use ipl\Web\Widget\Icon;
2222
use Iterator;
23-
use LimitIterator;
24-
use NoRewindIterator;
2523
use Traversable;
2624

2725
use function ipl\Stdlib\iterable_value_first;
@@ -220,9 +218,9 @@ protected function getCommands(Iterator $objects): Traversable
220218
}
221219

222220
$granted->rewind(); // Forwards the pointer to the first element
223-
while ($granted->valid()) {
221+
if ($granted->valid()) {
224222
// Chunk objects to avoid timeouts with large sets
225-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 250));
223+
yield $command->setObjects($granted)->setChunkSize(250);
226224
}
227225
}
228226
}

application/forms/Command/Object/AddCommentForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use ipl\Web\FormDecorator\IcingaFormDecorator;
2121
use ipl\Web\Widget\Icon;
2222
use Iterator;
23-
use LimitIterator;
24-
use NoRewindIterator;
2523
use Traversable;
2624

2725
use function ipl\Stdlib\iterable_value_first;
@@ -163,9 +161,9 @@ protected function getCommands(Iterator $objects): Traversable
163161
}
164162

165163
$granted->rewind(); // Forwards the pointer to the first element
166-
while ($granted->valid()) {
164+
if ($granted->valid()) {
167165
// Chunk objects to avoid timeouts with large sets
168-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 500));
166+
yield $command->setObjects($granted)->setChunkSize(500);
169167
}
170168
}
171169
}

application/forms/Command/Object/CheckNowForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use ipl\Orm\Model;
1212
use ipl\Web\Widget\Icon;
1313
use Iterator;
14-
use LimitIterator;
15-
use NoRewindIterator;
1614
use Traversable;
1715

1816
class CheckNowForm extends CommandForm
@@ -63,9 +61,9 @@ protected function getCommands(Iterator $objects): Traversable
6361
$command->setForced();
6462

6563
$granted->rewind(); // Forwards the pointer to the first element
66-
while ($granted->valid()) {
64+
if ($granted->valid()) {
6765
// Chunk objects to avoid timeouts with large sets
68-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 1000));
66+
yield $command->setObjects($granted)->setChunkSize(1000);
6967
}
7068
}
7169
}

application/forms/Command/Object/DeleteCommentForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use ipl\Orm\Model;
1212
use ipl\Web\Widget\Icon;
1313
use Iterator;
14-
use LimitIterator;
15-
use NoRewindIterator;
1614
use Traversable;
1715

1816
class DeleteCommentForm extends CommandForm
@@ -64,9 +62,9 @@ protected function getCommands(Iterator $objects): Traversable
6462
$command->setAuthor($this->getAuth()->getUser()->getUsername());
6563

6664
$granted->rewind(); // Forwards the pointer to the first element
67-
while ($granted->valid()) {
65+
if ($granted->valid()) {
6866
// Chunk objects to avoid timeouts with large sets
69-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 500));
67+
yield $command->setObjects($granted)->setChunkSize(500);
7068
}
7169
}
7270
}

application/forms/Command/Object/DeleteDowntimeForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use ipl\Orm\Model;
1212
use ipl\Web\Widget\Icon;
1313
use Iterator;
14-
use LimitIterator;
15-
use NoRewindIterator;
1614
use Traversable;
1715

1816
class DeleteDowntimeForm extends CommandForm
@@ -77,9 +75,9 @@ protected function getCommands(Iterator $objects): Traversable
7775
$command->setAuthor($this->getAuth()->getUser()->getUsername());
7876

7977
$granted->rewind(); // Forwards the pointer to the first element
80-
while ($granted->valid()) {
78+
if ($granted->valid()) {
8179
// Chunk objects to avoid timeouts with large sets
82-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 250));
80+
yield $command->setObjects($granted)->setChunkSize(250);
8381
}
8482
}
8583
}

application/forms/Command/Object/ProcessCheckResultForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use ipl\Web\FormDecorator\IcingaFormDecorator;
1717
use ipl\Web\Widget\Icon;
1818
use Iterator;
19-
use LimitIterator;
20-
use NoRewindIterator;
2119
use Traversable;
2220

2321
use function ipl\Stdlib\iterable_value_first;
@@ -154,9 +152,9 @@ protected function getCommands(Iterator $objects): Traversable
154152
$command->setPerformanceData($this->getValue('perfdata'));
155153

156154
$granted->rewind(); // Forwards the pointer to the first element
157-
while ($granted->valid()) {
155+
if ($granted->valid()) {
158156
// Chunk objects to avoid timeouts with large sets
159-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 250));
157+
yield $command->setObjects($granted)->setChunkSize(250);
160158
}
161159
}
162160
}

application/forms/Command/Object/RemoveAcknowledgementForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use ipl\Orm\Model;
1313
use ipl\Web\Widget\Icon;
1414
use Iterator;
15-
use LimitIterator;
16-
use NoRewindIterator;
1715
use Traversable;
1816

1917
use function ipl\Stdlib\iterable_value_first;
@@ -77,9 +75,9 @@ protected function getCommands(Iterator $objects): Traversable
7775
$command->setAuthor($this->getAuth()->getUser()->getUsername());
7876

7977
$granted->rewind(); // Forwards the pointer to the first element
80-
while ($granted->valid()) {
78+
if ($granted->valid()) {
8179
// Chunk objects to avoid timeouts with large sets
82-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 250));
80+
yield $command->setObjects($granted)->setChunkSize(250);
8381
}
8482
}
8583
}

application/forms/Command/Object/ScheduleCheckForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
use ipl\Web\FormDecorator\IcingaFormDecorator;
1919
use ipl\Web\Widget\Icon;
2020
use Iterator;
21-
use LimitIterator;
22-
use NoRewindIterator;
2321
use Traversable;
2422

2523
use function ipl\Stdlib\iterable_value_first;
@@ -129,9 +127,9 @@ protected function getCommands(Iterator $objects): Traversable
129127
$command->setCheckTime($this->getValue('check_time')->getTimestamp());
130128

131129
$granted->rewind(); // Forwards the pointer to the first element
132-
while ($granted->valid()) {
130+
if ($granted->valid()) {
133131
// Chunk objects to avoid timeouts with large sets
134-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 1000));
132+
yield $command->setObjects($granted)->setChunkSize(1000);
135133
}
136134
}
137135
}

application/forms/Command/Object/ScheduleServiceDowntimeForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use ipl\Web\FormDecorator\IcingaFormDecorator;
2020
use ipl\Web\Widget\Icon;
2121
use Iterator;
22-
use LimitIterator;
23-
use NoRewindIterator;
2422
use Traversable;
2523

2624
class ScheduleServiceDowntimeForm extends CommandForm
@@ -290,9 +288,9 @@ protected function getCommands(Iterator $objects): Traversable
290288
}
291289

292290
$granted->rewind(); // Forwards the pointer to the first element
293-
while ($granted->valid()) {
291+
if ($granted->valid()) {
294292
// Chunk objects to avoid timeouts with large sets
295-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 250));
293+
yield $command->setObjects($granted)->setChunkSize(250);
296294
}
297295
}
298296
}

application/forms/Command/Object/SendCustomNotificationForm.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use ipl\Web\FormDecorator\IcingaFormDecorator;
1818
use ipl\Web\Widget\Icon;
1919
use Iterator;
20-
use LimitIterator;
21-
use NoRewindIterator;
2220
use Traversable;
2321

2422
use function ipl\Stdlib\iterable_value_first;
@@ -130,9 +128,9 @@ protected function getCommands(Iterator $objects): Traversable
130128
$command->setAuthor($this->getAuth()->getUser()->getUsername());
131129

132130
$granted->rewind(); // Forwards the pointer to the first element
133-
while ($granted->valid()) {
131+
if ($granted->valid()) {
134132
// Chunk objects to avoid timeouts with large sets
135-
yield $command->setObjects(new LimitIterator(new NoRewindIterator($granted), 0, 500));
133+
yield $command->setObjects($granted)->setChunkSize(500);
136134
}
137135
}
138136
}

0 commit comments

Comments
 (0)