Skip to content

Commit

Permalink
Merge pull request #262 from tripal/fix-progress
Browse files Browse the repository at this point in the history
Check if we have queue items first
  • Loading branch information
almasaeed2010 authored Apr 1, 2019
2 parents dd9ffe6 + 2871c88 commit 46d5799
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions includes/Elasticsearch/ESQueue.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ESQueue{
class ESQueue {

/**
* Name of the queue progress table.
Expand Down Expand Up @@ -54,7 +54,15 @@ public function __construct() {
* @return object
*/
public static function progress() {
$query = 'SELECT index_name,
$should_check = (int) db_query("SELECT COUNT(*)
FROM queue
WHERE name LIKE :es", [
':es' => db_like('elasticsearch').'%',
])->fetchField();

$queues = [];
if ($should_check) {
$query = 'SELECT index_name,
priority,
SUM(total) AS total,
SUM(completed) AS completed,
Expand All @@ -63,7 +71,8 @@ public static function progress() {
FROM {' . self::QUEUE_TABLE . '}
GROUP BY index_name, priority
ORDER BY index_name ASC, priority ASC';
$queues = db_query($query)->fetchAll();
$queues = db_query($query)->fetchAll();
}

$progress = [];
$total = 0;
Expand All @@ -76,7 +85,7 @@ public static function progress() {
continue;
}

if($queue->completed > $queue->total) {
if ($queue->completed > $queue->total) {
static::fixProgress($queue);
}

Expand All @@ -100,7 +109,7 @@ public static function progress() {
'last_run_at' => $last_run,
'started_at' => $started_at,
'time' => $queue->last_run_at - $queue->started_at,
'priority' => $queue->priority
'priority' => $queue->priority,
];
}

Expand All @@ -117,7 +126,7 @@ public static function progress() {
public static function fixProgress(&$queue) {
$queue->completed = $queue->total;

db_query('UPDATE {'.self::QUEUE_TABLE.'} SET completed=total WHERE completed > total');
db_query('UPDATE {' . self::QUEUE_TABLE . '} SET completed=total WHERE completed > total');
}

/**
Expand Down Expand Up @@ -301,4 +310,4 @@ protected function generateQueueCount() {
}
}
}
}
}

0 comments on commit 46d5799

Please sign in to comment.