Skip to content

Commit

Permalink
DDST-58: Updates post Adam's commit pull
Browse files Browse the repository at this point in the history
  • Loading branch information
axelerant-hardik committed May 7, 2024
1 parent 3ff98be commit 4c7d49e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/Commands/RebuildOaiEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,31 @@ public function rebuild(array $options = [
*/
public function rebuildBatch(int $batch_size, &$context) {
$queue = $this->queue->get('rest_oai_pmh_views_cache_cron');

// Setting the defaults.
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['total'] = $queue->numberOfItems();
$context['sandbox']['processed_items'] = 0;
$context['sandbox']['total_items'] = $queue->numberOfItems();
}

$item = $queue->claimItem();
if (!$item) {
// Queue exhausted; we're done. Shouldn't strictly be necessary, but we could explicitly
// set `$context['finished'] = 1;` if we wanted to.
// Queue exhausted; we're done.
$context['finished'] = 1;
return;
}

rest_oai_pmh_process_queue($item);

$context['sandbox']['processed_items']++;

$context['finished'] = $context['sandbox']['processed_items'] / (
// XXX: Force queue exhaustion above to terminate.
$context['sandbox']['processed_items'] >= $context['sandbox']['total_items'] ?
$context['sandbox']['processed_items'] + 1 :
$context['sandbox']['total_items']
));

$start = $context['sandbox']['processed_items'];
$end = $start + $batch_size;
$end = min($end, $context['sandbox']['total_items']);

while ($context['sandbox']['processed_items'] < $end) {
rest_oai_pmh_process_queue($item);
$context['sandbox']['processed_items']++;
}

// Set the batch progress percentage.
$context['finished'] = $context['sandbox']['processed_items'] / $context['sandbox']['total_items'];
}

}

0 comments on commit 4c7d49e

Please sign in to comment.