From 78ebf9993fbc2009625ed75beeb6c50835c65786 Mon Sep 17 00:00:00 2001 From: jcarter Date: Thu, 22 Nov 2018 09:52:28 +1100 Subject: [PATCH] add(CleanupJob): query_limit config option (default 100k) --- code/jobs/CleanupJob.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/code/jobs/CleanupJob.php b/code/jobs/CleanupJob.php index 67f6fa2f..60c21b7d 100644 --- a/code/jobs/CleanupJob.php +++ b/code/jobs/CleanupJob.php @@ -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 @@ -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 @@ -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; @@ -115,7 +129,7 @@ public function process() { WHERE "ID" NOT IN (\'' . $freshJobIDs . '\') AND "JobStatus" - IN (\'' . $statusList . '\')' + IN (\'' . $statusList . '\')' . $limit ); $staleJobs = $stale->column("ID"); break; @@ -151,4 +165,4 @@ private function reenqueue() } } -} +} \ No newline at end of file