t('General'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => FALSE, ); $form['general']['ultimate_cron_simultaneous_connections'] = array( '#title' => t("Simultaneous connections"), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_simultaneous_connections', ULTIMATE_CRON_SIMULTANEOUS_CONNECTIONS), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'simultaneous_connections', 'type' => 'icon') ) : '') . t('Maximum number of simultaneous connections'), ); $form['general']['ultimate_cron_rule'] = array( '#title' => t("Default rule"), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_rule', ULTIMATE_CRON_RULE), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'rules', 'type' => 'icon') ) : '') . t('Enter the default fallback rule'), ); $form['general']['ultimate_cron_cleanup_log'] = array( '#title' => t("Clean up logs older than X seconds"), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_cleanup_log', ULTIMATE_CRON_CLEANUP_LOG), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'cleanup_log', 'type' => 'icon') ) : '') . t('Enter maximum age, in seconds, for log entries'), ); $form['general']['ultimate_cron_catch_up'] = array( '#title' => t('Default catch up'), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'catch_up', 'type' => 'icon') ) : '') . t('Time in seconds to catch up, if a job could not be run within its time frame. (blank = ' . variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP) . ')'), ); $form['general']['ultimate_cron_queue_polling_latency'] = array( '#title' => t("Queue polling latency"), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_queue_polling_latency', ULTIMATE_CRON_QUEUE_POLLING_LATENCY), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'polling_latency', 'type' => 'icon') ) : '') . t('Queue polling latency in miliseconds. Leave blank to disable continuous processing of queues.'), ); $form['general']['ultimate_cron_queue_lease_time'] = array( '#title' => t('Queue lease time'), '#type' => 'textfield', '#default_value' => variable_get('ultimate_cron_queue_lease_time', ULTIMATE_CRON_QUEUE_LEASE_TIME), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'queue_lease_time', 'type' => 'icon') ) : '') . t('Time in seconds to keep lock on claimed item'), ); $methods = module_invoke_all('service_group'); $options = ultimate_cron_get_service_groups(); foreach ($options as $key => &$value) { $value = (empty($value['description']) ? $key : $value['description']) . ' (' . join(',', $value['hosts']) . ') : ' . $methods['methods'][$value['method']]; } $form['general']['ultimate_cron_service_group'] = array( '#type' => 'select', '#title' => t('Service group'), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'service_group', 'type' => 'icon') ) : '') . t('Service group to use for all jobs. See Background Process !url for managing service groups.', array('!url' => l(t('settings'), 'admin/config/system/background-process'))), '#options' => $options, '#default_value' => variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP), ); $form['general']['ultimate_cron_poorman'] = array( '#title' => t("Poormans cron"), '#type' => 'checkbox', '#default_value' => variable_get('ultimate_cron_poorman', ULTIMATE_CRON_POORMAN), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'poorman', 'type' => 'icon') ) : '') . t('Keep background process alive, checking for cron every minute.'), ); $form = system_settings_form($form); return $form; } /** * Function settings form. */ function ultimate_cron_function_settings_form($form, &$form_state, $function) { $hooks = ultimate_cron_get_hooks(); if (!isset($hooks[(string)$function])) { drupal_not_found(); exit; } // Load settings $hook = $hooks[$function]; $conf = ultimate_cron_get_settings($function); $conf += _ultimate_cron_default_settings(); // Setup form drupal_set_title(check_plain($function)); $form = array(); $advanced_help_enabled = module_exists('advanced_help'); // General settings ----------------------------------- $form['function'] = array( '#type' => 'value', '#value' => $function, ); $form['general'] = array( '#title' => t('General'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, ); $form['general']['enabled'] = array( '#title' => t('Enabled'), '#type' => 'checkbox', '#default_value' => $conf['enabled'], '#description' => t('Enable this cron job.'), ); $form['general']['rules'] = array( '#title' => t('Rules'), '#type' => 'textfield', '#default_value' => implode(';', $conf['rules']), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'rules', 'type' => 'icon') ) : '') . t('Semi-colon separated list of rules for this job. (blank = ' . implode(';', $hook['settings']['rules']) . ')'), ); $form['general']['catch_up'] = array( '#title' => t('Catch up'), '#type' => 'textfield', '#default_value' => $conf['catch_up'], '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'catch_up', 'type' => 'icon') ) : '') . t('Time in seconds to catch up, if a job could not be run within its time frame. (blank = ' . variable_get('ultimate_cron_catch_up', ULTIMATE_CRON_CATCH_UP) . ')'), ); if (strpos($function, 'ultimate_cron_queue_') === 0) { $form['general']['queue_lease_time'] = array( '#title' => t('Queue lease time'), '#type' => 'textfield', '#default_value' => $conf['queue_lease_time'], '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'queue_lease_time', 'type' => 'icon') ) : '') . t('Time in seconds to keep lock on claimed item. (blank = ' . variable_get('ultimate_cron_queue_lease_time', ULTIMATE_CRON_QUEUE_LEASE_TIME) . ')'), ); } $methods = module_invoke_all('service_group'); $service_groups = $options = ultimate_cron_get_service_groups(); foreach ($options as $key => &$value) { $value = (empty($value['description']) ? $key : $value['description']) . ' (' . join(',', $value['hosts']) . ') : ' . $methods['methods'][$value['method']]; } $options += array( NULL => 'Ultimate Cron service group (' . join(',', $service_groups[variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP)]['hosts']) . ') : ' . $methods['methods'][$service_groups[variable_get('ultimate_cron_service_group', ULTIMATE_CRON_SERVICE_GROUP)]['method']] ); $form['general']['service_group'] = array( '#type' => 'select', '#title' => t('Service group'), '#description' => ($advanced_help_enabled ? theme('advanced_help_topic', array( 'module' => 'ultimate_cron', 'topic' => 'service_group', 'type' => 'icon') ) : '') . t('Service group to use for this job. See Background Process !url for managing service groups.', array('!url' => l(t('settings'), 'admin/config/system/background-process'))), '#options' => $options, '#default_value' => isset($conf['service_group']) ? $conf['service_group'] : NULL, ); $form['buttons'] = array( '#weight' => 1000, ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Save settings'), ); $form['#redirect'] = 'admin/config/system/cron'; return $form; } /** * Validate handler for function settings. */ function ultimate_cron_function_settings_form_validate($form, &$form_state) { $conf =& $form_state['values']['general']; $conf['rules'] = trim($conf['rules']); $conf['rules'] = $conf['rules'] ? explode(';', $conf['rules']) : array(); if ($conf['rules']) { foreach ($conf['rules'] as &$rule) { $rule = trim($rule); if (!ultimate_cron_validate_rule($rule)) { form_set_error('rules', t('Invalid rule.')); } } } else { unset($conf['rules']); } } /** * Submit handler for function settings. */ function ultimate_cron_function_settings_form_submit($form, &$form_state) { $conf =& $form_state['values']['general']; ultimate_cron_set_settings($form_state['values']['function'], $conf); unset($form_state['storage']); } /** * Page overviewing cron jobs. */ function ultimate_cron_view_page($module = NULL) { require_once 'CronRule.class.php'; drupal_add_css(drupal_get_path('module', 'ultimate_cron') . '/css/ultimate_cron.admin.css'); drupal_add_js(drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.js'); if (module_exists('nodejs')) { drupal_add_js(array( 'ultimate_cron' => array( 'processes' => new stdClass(), 'skew' => 0, ), ), 'setting'); nodejs_send_content_channel_token('ultimate_cron'); nodejs_send_content_channel_token('background_process'); nodejs_send_content_channel_token('progress'); drupal_add_js(drupal_get_path('module', 'ultimate_cron') . '/js/nodejs.ultimate_cron.js'); } module_load_install('ultimate_cron'); $requirements = ultimate_cron_requirements('runtime'); if ($requirements['ultimate_cron']['severity'] != REQUIREMENT_OK) { drupal_set_message($requirements['ultimate_cron']['value'], 'error'); drupal_set_message($requirements['ultimate_cron']['description'], 'error'); } // Get hooks and their data $data = _ultimate_cron_preload_cron_data(); $hooks = ultimate_cron_get_hooks(); $modules = array(); foreach ($hooks as $function => $hook) { if (!$module || $module == $hook['module']) { $hook['settings'] = $data[$function]['settings'] + $hook['settings']; $hook['background_process'] = $data[$function]['background_process']; $hook['log'] = ultimate_cron_get_log($function); $modules[$hook['module']][$function] = $hook; } } $headers = array('', t('Module'), t('Function'), t('Rules'), t('Start'), t('Duration'), t('Status'), array('colspan' => 3, 'data' => ''), l(t('Run all'), 'admin/reports/status/run-cron', array('query' => drupal_get_destination()))); $output = ''; $links = array( '' . t('Errors') . '', '' . t('Success') . '', '' . t('Running') . '', '' . t('All') . '', ); $output .= theme('item_list', array('items' => $links, 'attributes' => array('class' => 'tabs secondary ultimate-cron-admin-status-tabs'))); $output .= '
'; $rows = array(); $overview = array(); $overview['running'] = 0; $overview['errors'] = 0; // Used for JS encodeURIComponent emulation $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'); foreach ($modules as $module => $hooks) { foreach ($hooks as $function => $hook) { // Setup settings $conf = $hook['settings']; $rules = $hook['settings']['rules']; $cron = new CronRule(); $parsed_rules = array(); foreach ($rules as $rule) { $cron->rule = $rule; $cron->offset = $hook['delta']; $parsed_rules[] = $cron->parseRule(); } // Setup process $process = $hook['background_process']; $service_host = empty($process->service_host) ? t('N/A') : $process->service_host; // Setup log $log = $hook['log']; if (!$log) { $log = array( 'status' => NULL, 'start' => NULL, 'end' => NULL, ); } $short_msg = isset($log['status']) ? ($log['status'] ? t('No errors') : t('Errors')) : t('No information'); $css_status = !empty($process) ? 'running' : (isset($log['status']) ? ($log['status'] ? 'noerror' : 'error') : 'noinfo'); $msg = !empty($log['msg']) ? $log['msg'] : ($log['status'] ? t('No errors') : t('No information')); $duration = ''; if ($process) { $overview['running']++; $log['previous_start'] = $log['start']; $log['previous_end'] = $log['end']; $log['start'] = $process->start; if ($process->status == BACKGROUND_PROCESS_STATUS_RUNNING) { $log['end'] = microtime(TRUE); } else { $log['end'] = NULL; } $progress = progress_get_progress('uc:' . $function); if ($progress && $progress->progress > 0) { $duration .= sprintf(" (%d%%)", $progress->progress * 100); } } if (isset($log['status']) && !$log['status']) { $overview['errors']++; } $link_configure = ''; if (!empty($hook['configure'])) { $link_configure = _ultimate_cron_l('Settings', $hook['configure']); } $link_unlock = ''; if ($process) { $link_unlock = _ultimate_cron_l('Unlock', 'background-process/unlock/' . $process->handle); } $link_settings = _ultimate_cron_l('Schedule', 'admin/config/system/cron/settings/' . $function); $link_execute = _ultimate_cron_l('Run', 'admin/ultimate-cron/service/start/' . $function); $link_log = _ultimate_cron_l('Log', 'admin/reports/cron/' . $function); $enable = !empty($conf) && empty($conf['enabled']); $link_toggle = _ultimate_cron_l($enable ? 'Enable' : 'Disable', 'admin/ultimate-cron/service/' . ($enable ? 'enable' : 'disable') . '/' . $function); $data = array( array('class' => $enable ? 'ultimate-cron-admin-enable' : 'ultimate-cron-admin-disable'), array('class' => 'ultimate-cron-admin-module'), array('class' => 'ultimate-cron-admin-function'), array('class' => 'ultimate-cron-admin-rules'), array('class' => 'ultimate-cron-admin-start'), array('class' => 'ultimate-cron-admin-end'), array('class' => 'ultimate-cron-admin-status ultimate-cron-admin-status-' . $css_status), array('class' => 'ultimate-cron-admin-settings'), array('class' => 'ultimate-cron-admin-configure'), array('class' => 'ultimate-cron-admin-log'), array('class' => $process ? 'ultimate-cron-admin-unlock' : 'ultimate-cron-admin-execute'), ); $data[0]['data'] = $link_toggle; $data[0]['title'] = $enable ? t('Enable') : t('Disable'); $data[1]['data'] = ultimate_cron_module_name($module); $data[2]['data'] = $hook['description']; $data[2]['title'] = $function; $data[3]['data'] = join("