function elysia_cron_run in Elysia Cron 6
Same name and namespace in other branches
- 5.2 elysia_cron.module \elysia_cron_run()
- 5 elysia_cron.module \elysia_cron_run()
- 6.2 elysia_cron.module \elysia_cron_run()
- 7.2 elysia_cron.module \elysia_cron_run()
- 7 elysia_cron.module \elysia_cron_run()
4 calls to elysia_cron_run()
- cron.php in ./cron.php
- drush_elysia_cron_run_wrapper in ./elysia_cron.drush.inc
- A drush command callback.
- elysia_cron_cron in ./elysia_cron.module
- Hook cron is invoked only by standard drupal cron.
It's used to replace drupal cron.
- elysia_cron_run_form_submit in ./elysia_cron.admin.inc
1 string reference to 'elysia_cron_run'
- cron.php in ./cron.php
File
- ./elysia_cron.module, line 861
Code
function elysia_cron_run($manual_run = false) {
global $conf;
@ignore_user_abort(true);
if (!ini_get('safe_mode')) {
set_time_limit(variable_get('elysia_cron_time_limit', 240));
}
if (EC_DRUPAL_VERSION >= 7) {
drupal_save_session(FALSE);
}
if (variable_get('elysia_cron_disabled', false)) {
return;
}
if (!$manual_run) {
$cron_key = variable_get('cron_key', '');
if ($cron_key && !user_access('administer elysia_cron') && (empty($_GET['cron_key']) || $_GET['cron_key'] != $cron_key)) {
return;
}
$allowed_hosts = variable_get('elysia_cron_allowed_hosts', false);
if ($allowed_hosts && !user_access('administer elysia_cron') && !in_array(ip_address(), explode(",", $allowed_hosts))) {
return;
}
}
_ec_variable_set('elysia_cron_last_run', time());
_ec_variable_set('cron_last', time());
$execute = true;
if (EC_DRUPAL_VERSION >= 7) {
if (!lock_acquire('cron', 240.0)) {
_dco_watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING);
$execute = false;
}
}
else {
$execute = _ec_semaphore_get('elysia_cron_semaphore', 120);
}
if ($manual_run) {
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
}
if (EC_DRUPAL_VERSION >= 7) {
$queues = module_invoke_all('cron_queue_info');
drupal_alter('cron_queue_info', $queues);
}
if ($execute) {
if (EC_DRUPAL_VERSION >= 7) {
foreach ($queues as $queue_name => $info) {
DrupalQueue::get($queue_name)
->createQueue();
}
}
elysia_cron_initialize();
global $elysia_cron_settings, $elysia_cron_settings_by_channel, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
$channels = array_keys($elysia_cron_settings_by_channel);
$channel = elysia_cron_last_channel();
$i = array_search($channel, $channels);
if ($i === FALSE) {
$i = -1;
}
$k = 0;
$jobs = false;
$stuck_time = variable_get('elysia_cron_stuck_time', 3600);
for ($j = ($i + 1) % count($channels); $k < count($channels); $j = ($j + 1) % count($channels)) {
$sem = elysia_cron_is_channel_running($channels[$j]);
if ($sem && time() - $sem > $stuck_time) {
elysia_cron_set_channel_running($channels[$j], 0);
$last_job = elysia_cron_execute_aborted($channels[$j]);
unset($sem);
_dco_watchdog('cron', 'Cron channel (%channel) has been running for more than an %stuck_time secs and is most likely stuck. Last job executed: %job', array(
'%channel' => $channels[$j],
'%stuck_time' => $stuck_time,
'%job' => $last_job,
), WATCHDOG_ERROR);
}
if (empty($sem) && !$elysia_cron_settings_by_channel[$channels[$j]]['#data']['disabled']) {
$jobs = elysia_cron_active_jobs($channels[$j]);
if (count($jobs)) {
break;
}
}
$k++;
}
if ($jobs && count($jobs)) {
$elysia_cron_current_channel = $channels[$j];
elysia_cron_set_last_channel($elysia_cron_current_channel);
if (variable_get('elysia_cron_debug_messages', 0)) {
_dco_watchdog('cron', 'Cron channel %channel run started.', array(
'%channel' => $elysia_cron_current_channel,
), WATCHDOG_NOTICE);
}
register_shutdown_function('elysia_cron_cleanup');
elysia_cron_set($elysia_cron_current_channel, true, array(
'running' => time(),
'last_run' => time(),
));
if (EC_DRUPAL_VERSION < 7) {
_ec_variable_del('elysia_cron_semaphore');
$conf['cron_semaphore'] = time();
}
foreach ($jobs as $job) {
$job_running = false;
if (elysia_cron_is_job_running($job)) {
if (time() - elysia_cron_get_job_last_run($job, 0) > variable_get('elysia_cron_stuck_time', 3600)) {
_dco_watchdog('cron', 'Job %job is already running, but is probably stuck, so i consider it as terminated', array(
'%job' => $job,
), WATCHDOG_NOTICE);
}
else {
_dco_watchdog('cron', 'Job %job is already running', array(
'%job' => $job,
), WATCHDOG_NOTICE);
$job_running = true;
}
}
if (!$job_running) {
elysia_cron_execute($job);
}
}
$cron_completed = true;
$cron_completed_time = time();
register_shutdown_function('elysia_cron_completed');
}
else {
if (EC_DRUPAL_VERSION < 7) {
_ec_variable_del('elysia_cron_semaphore');
}
if (variable_get('elysia_cron_debug_messages', 0)) {
_dco_watchdog('cron', 'No channels ready to be executed, skipping cron.', array(), WATCHDOG_NOTICE);
}
}
if (EC_DRUPAL_VERSION >= 7) {
lock_release('cron');
}
else {
_ec_variable_del('cron_semaphore');
$conf['cron_semaphore'] = false;
}
}
if (EC_DRUPAL_VERSION >= 7) {
foreach ($queues as $queue_name => $info) {
$function = $info['worker callback'];
$end = time() + (isset($info['time']) ? $info['time'] : 15);
$queue = DrupalQueue::get($queue_name);
while (time() < $end && ($item = $queue
->claimItem())) {
$function($item->data);
$queue
->deleteItem($item);
}
}
}
if ($manual_run) {
$GLOBALS['user'] = $original_user;
}
return $execute;
}