function hosting_cron_queue in Hostmaster (Aegir) 6
Implementation of hosting_QUEUE_TYPE_queue().
File
- modules/
hosting/ cron/ hosting_cron.module, line 29 - Allow the hosting system to cron all the installed sites on a schedule.
Code
function hosting_cron_queue($count) {
$result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {hosting_site} s ON n.nid=s.nid WHERE n.type='site' and s.status = %d ORDER BY s.last_cron ASC, n.nid ASC", HOSTING_SITE_ENABLED);
$i = 0;
while ($i < $count && ($nid = db_fetch_object($result))) {
$site = node_load($nid->nid);
$site_name = hosting_context_name($site->nid);
if (variable_get('hosting_cron_use_backend', TRUE)) {
provision_backend_invoke($site_name, "cron");
}
else {
// Optionally add the cron_key querystring key if the site has one.
$url = _hosting_site_url($site) . '/cron.php';
if (!empty($site->cron_key)) {
$url .= '?cron_key=' . rawurlencode($site->cron_key);
}
drush_log(dt("running cron on URL %url", array(
'%url' => $url,
)));
$response = drupal_http_request($url);
if (isset($response->error) && $response->error) {
watchdog('hosting_cron', 'cron failed on site %site with error %error', array(
'%site' => $site->title,
'%error' => $response->error,
), WATCHDOG_NOTICE);
continue;
// don't update the timestamp
}
}
// We are updating the site table here directly to avoid a possible race condition,
// with the task queue. There exists a chance that they might both try to save the
// same node at the same time, and then an old record from the cron queue might
// replace the newly updated record.
db_query("UPDATE {hosting_site} SET last_cron=%d WHERE nid=%d", time(), $site->nid);
$i++;
}
}