diff --git a/hosting.api.php b/hosting.api.php index 138b71a..4c2ab4f 100644 --- a/hosting.api.php +++ b/hosting.api.php @@ -312,7 +312,7 @@ function hosting_QUEUE_TYPE_queue($count = 5) { global $provision_errors; drush_log(dt("Running tasks queue")); - $tasks = _hosting_get_new_tasks($count); + $tasks = hosting_get_new_tasks($count); foreach ($tasks as $task) { drush_invoke_process('@self', "hosting-task", array($task->nid), array(), array('fork' => TRUE)); } diff --git a/queued/hosting_queued.drush.inc b/queued/hosting_queued.drush.inc index 4a8d9c1..b13af3a 100644 --- a/queued/hosting_queued.drush.inc +++ b/queued/hosting_queued.drush.inc @@ -73,7 +73,7 @@ function drush_hosting_queued() { // Get some tasks to run - if ($tasks = @_hosting_get_new_tasks()) { + if ($tasks = @hosting_get_new_tasks()) { if (lock_acquire('hosting_queue_tasks_running', HOSTING_QUEUE_LOCK_TIMEOUT)) { drush_log('Acquired lock on task queue.'); foreach ($tasks as $task) { diff --git a/task/hosting_task.module b/task/hosting_task.module index 79419f0..d86c4bb 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -672,7 +672,7 @@ function hosting_tasks_queue($count = 20) { global $provision_errors; drush_log(dt("Running tasks queue")); - $tasks = _hosting_get_new_tasks($count); + $tasks = hosting_get_new_tasks($count); foreach ($tasks as $task) { drush_invoke_process('@self', "hosting-task", array($task->nid), array('strict' => FALSE), array('fork' => TRUE)); } @@ -1250,34 +1250,47 @@ function hosting_get_tasks($filter_by = NULL, $filter_value = NULL, $count = 5, } /** - * Retrieve a list of outstanding tasks. + * Retrieve a list of outstanding, queued, tasks. * * @param int $limit - * The amount of items to return. + * The maximum number of tasks to return. + * * @return array * An associative array containing task nodes, indexed by node id. */ -function _hosting_get_new_tasks($limit = 20) { +function hosting_get_new_tasks($limit = 20) { $return = array(); - $result = db_query_range("SELECT t.nid - FROM {hosting_task} t - INNER JOIN {node} n - ON t.vid = n.vid - WHERE t.task_status = :task_status - GROUP BY t.rid - ORDER BY n.changed, n.nid ASC", - 0, - $limit, - array( - ':task_status' => HOSTING_TASK_QUEUED, - )); - foreach ($result as $node) { + + $query = db_select('hosting_task', 't'); + $query->innerJoin('node', 'n', 't.vid = n.vid'); + $query + ->fields('t', array('nid')) + ->condition('t.task_status', HOSTING_TASK_QUEUED) + ->orderBy('n.changed') + ->orderBy('n.nid') + ->groupBy('t.rid') + ->range(0, $limit) + ->addTag('hosting_get_new_tasks'); + + foreach ($query->execute() as $node) { $return[$node->nid] = node_load($node->nid); } return $return; } /** + * Retrieve a list of outstanding, queued, tasks. + * + * @deprecated First deprecated in Hosting 3.6 because this function was made + * part of the public API, use hosting_get_new_tasks() instead. + * + * @see hosting_get_new_tasks + */ +function _hosting_get_new_tasks($limit = 20) { + return hosting_get_new_tasks($limit); +} + +/** * @name Error status definitions * @{ * Bitmask values used to generate the error code to return.