Skip to content

Commit bae2aec

Browse files
Handles timeouts more gracefully in maintenance tools
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
1 parent 223172a commit bae2aec

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Sources/Maintenance/Migration/MigrationBase.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,25 @@ public function execute(): bool
6464
/**
6565
* Wrapper for the tool to handle timeout protection.
6666
*
67-
* If a timeout needs to occur, it is handled, ensure that prior to this call, all variables are updated..
67+
* @param ?int $start If set, the current start value will be set to this
68+
* value before the timeout check itself occurs.
6869
*/
6970
protected function handleTimeout(?int $start = null): void
7071
{
7172
if ($start !== null) {
7273
Maintenance::setCurrentStart($start);
7374
}
7475

75-
Maintenance::$tool->checkAndHandleTimeout();
76+
Maintenance::$tool->checkAndHandleTimeout([
77+
'name' => $this->name,
78+
'completed' => false,
79+
'substep' => Maintenance::getCurrentSubStep(),
80+
'start' => Maintenance::getCurrentStart(),
81+
'total' => Maintenance::$total_substeps,
82+
'debug' => [
83+
'call' => $this::class,
84+
],
85+
]);
7686
}
7787

7888
/**

Sources/Maintenance/Tools/ToolsBase.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,31 @@ final public function detectLanguages(array $key_files = ['General']): array
547547
}
548548

549549
/**
550-
* This will check if we need to handle a timeout, if so, it sets up data for the next round.
550+
* This will check if we need to handle a timeout, if so, it sets up data
551+
* for the next round.
551552
*
553+
* @param array $json_response_data Data to send in a JSON response if we
554+
* have timed out. This data is passed to Maintenance::jsonResponse().
555+
* Only used when Maintenance::isJson() returns true.
552556
* @throws \ValueError
553557
* @throws \Exception
554558
*/
555-
public function checkAndHandleTimeout(): void
559+
public function checkAndHandleTimeout(array $json_response_data = []): void
556560
{
557561
if (!Maintenance::isOutOfTime()) {
558562
return;
559563
}
560564

565+
$this->logProgress(Lang::getTxt('log_paused_step', ['num' => $this->getStep()->getId()], file: 'Maintenance'));
566+
561567
// If this is not json, we need to do a few things.
562568
if (!Maintenance::isJson()) {
563569
// We're going to pause after this!
564570
Maintenance::$context['pause'] = true;
565571

566572
Maintenance::setQueryString();
573+
} else {
574+
Maintenance::jsonResponse($json_response_data);
567575
}
568576

569577
Maintenance::exit(Maintenance::isJson());

0 commit comments

Comments
 (0)