Skip to content

Commit

Permalink
Offset to increase only when resend fails or dryrun mode
Browse files Browse the repository at this point in the history
 - Also order by id, to ensure the same order is given everytime
  • Loading branch information
ScottVerbeek committed Nov 5, 2023
1 parent ca794db commit ace093b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/resendfailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@

$sql = "SELECT x.id
FROM {{$basetable}} x
WHERE $where";
WHERE $where
ORDER BY x.id";

$limitfrom = 0;
$limitnum = $options['batch'];
Expand All @@ -140,28 +141,30 @@
$countfail = 0;

do {
cli_write("Reading at offset {$limitfrom} ...");
$records = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
$count = count($records);
$limitfrom += $count;
$counttotal += $count;
cli_writeln("Read {$count} records, next offset will be {$limitfrom}");
cli_writeln(" read {$count} records.");

$eventids = array_keys($records);

if (empty($eventids)) {
continue;
break;
}

$mover = new \logstore_xapi\log\moveback($eventids, XAPI_REPORT_ID_ERROR);

if ($options['dryrun']) {
$limitfrom += $count;
continue;
}

if ($mover->execute()) {
$countsucc += $count;
cli_writeln("$count events successfully sent for reprocessing.");
} else {
$limitfrom += $count; // Increase the offset, when failed to move.
$countfail += $count;
cli_writeln("$count events failed to send for reprocessing.");
}
Expand Down

0 comments on commit ace093b

Please sign in to comment.