Skip to content

Commit

Permalink
add(CleanupJob): query_limit config option (default 100k)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarter committed Nov 21, 2018
1 parent b0258b2 commit 78ebf99
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions code/jobs/CleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class CleanupJob extends AbstractQueuedJob implements QueuedJob {
// "Waiting",
);

/**
* Database query limit
* @config
* @var integer
*/
private static $query_limit = 100000;

/**
* Check whether is enabled or not for BC
* @config
Expand Down Expand Up @@ -79,6 +86,13 @@ public function getJobType() {
* Clear out stale jobs based on the cleanup values
*/
public function process() {
// construct limit statement if query_limit is valid int value
$limit = '';
$query_limit = $this->config()->get('query_limit');
if (is_numeric($query_limit) && $query_limit >= 0) {
$limit = ' LIMIT ' . ((int)$query_limit);
}

$statusList = implode('\', \'', $this->config()->cleanup_statuses);
switch($this->config()->cleanup_method) {
// If Age, we need to get jobs that are at least n days old
Expand All @@ -94,8 +108,8 @@ public function process() {
'SELECT "ID"
FROM "QueuedJobDescriptor"
WHERE "JobStatus"
IN (\'' . $statusList . '\')
AND "LastEdited" < \'' . $cutOff .'\''
IN (\'' . $statusList . '\')
AND "LastEdited" < \'' . $cutOff . '\'' . $limit
);
$staleJobs = $stale->column("ID");
break;
Expand All @@ -115,7 +129,7 @@ public function process() {
WHERE "ID"
NOT IN (\'' . $freshJobIDs . '\')
AND "JobStatus"
IN (\'' . $statusList . '\')'
IN (\'' . $statusList . '\')' . $limit
);
$staleJobs = $stale->column("ID");
break;
Expand Down Expand Up @@ -151,4 +165,4 @@ private function reenqueue()
}
}

}
}

0 comments on commit 78ebf99

Please sign in to comment.