Example #1
0
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
global $cjob_row, $current_User, $admin_url;
$Form = new Form(NULL, 'cronlog');
if (empty($cjob_row->clog_status) && $current_User->check_perm('options', 'edit', false, NULL)) {
    // User can edit this job:
    $Form->global_icon(T_('Edit this job'), 'edit', $admin_url . '?ctrl=crontab&action=edit&ctsk_ID=' . $cjob_row->ctsk_ID, T_('Edit this job...'), 3, 3);
}
$Form->global_icon(T_('Close sheet'), 'close', regenerate_url('action,cjob_ID'));
$manual_link = cron_job_manual_link($cjob_row->ctsk_key);
$Form->begin_form('fform', T_('Scheduled job'));
$Form->begin_fieldset(T_('Job details') . $manual_link);
$Form->info(T_('Job #'), $cjob_row->ctsk_ID);
$Form->info(T_('Job name'), cron_job_name($cjob_row->ctsk_key, $cjob_row->ctsk_name, $cjob_row->ctsk_params) . $manual_link);
$Form->info(T_('Scheduled at'), mysql2localedatetime($cjob_row->ctsk_start_datetime));
$cjob_repeat_after = '';
if ($cjob_repeat_after_days = floor($cjob_row->ctsk_repeat_after / 86400)) {
    $cjob_repeat_after .= $cjob_repeat_after_days . ' ' . T_('days') . ' ';
}
if ($cjob_repeat_after_hours = floor($cjob_row->ctsk_repeat_after % 86400 / 3600)) {
    $cjob_repeat_after .= $cjob_repeat_after_hours . ' ' . T_('hours') . ' ';
}
if ($cjob_repeat_after_minutes = floor($cjob_row->ctsk_repeat_after % 3600 / 60)) {
    $cjob_repeat_after .= $cjob_repeat_after_minutes . ' ' . T_('minutes');
}
$Form->info(T_('Repeat every'), $cjob_repeat_after);
$Form->end_fieldset();
$Form->begin_fieldset(T_('Execution details') . get_manual_link('scheduled-job-execution-details'));
if (empty($cjob_row->clog_status)) {
Example #2
0
$Form->begin_form('fform', $creating ? T_('New scheduled job') : T_('Edit scheduled job'));
$Form->add_crumb('crontask');
$Form->hiddens_by_key(get_memorized('action'));
$Form->hidden('action', $creating ? 'create' : 'update');
$Form->begin_fieldset(T_('Job details') . get_manual_link('scheduled-job-form'));
if ($creating && $action != 'copy') {
    // New cronjob
    $cron_jobs_names = get_cron_jobs_config('name');
    // Exclude these cron jobs from manual creating
    unset($cron_jobs_names['send-post-notifications']);
    unset($cron_jobs_names['send-comment-notifications']);
    $Form->select_input_array('cjob_type', get_param('cjob_type'), $cron_jobs_names, T_('Job type'));
} else {
    // Edit cronjob
    if ($action == 'edit') {
        $Form->info(T_('Job #'), $edited_Cronjob->ID);
    }
    $Form->info(T_('Default job name'), cron_job_name($edited_Cronjob->key, '', $edited_Cronjob->params));
    $Form->text_input('cjob_name', $edited_Cronjob->name, 50, T_('Job name'), '', array('maxlength' => 255));
}
$Form->date_input('cjob_date', date2mysql($edited_Cronjob->start_timestamp), T_('Schedule date'), array('required' => true));
$Form->time_input('cjob_time', date2mysql($edited_Cronjob->start_timestamp), T_('Schedule time'), array('required' => true));
$Form->duration_input('cjob_repeat_after', $edited_Cronjob->repeat_after, T_('Repeat every'), 'days', 'minutes', array('minutes_step' => 1));
$Form->end_fieldset();
if (!$creating) {
    // We can edit only pending cron jobs, Show this field just for info
    $Form->begin_fieldset(T_('Execution details') . get_manual_link('scheduled-job-execution-details'));
    $Form->info(T_('Status'), 'pending');
    $Form->end_fieldset();
}
$Form->end_form(array(array('submit', 'submit', $creating ? T_('Create') : T_('Save Changes!'), 'SaveButton')));
Example #3
0
 * The trick is to rely on the primary key of the cron__log table.
 */
// Get next task to run in queue which has not started execution yet:
$sql = 'SELECT *
					FROM T_cron__task LEFT JOIN T_cron__log ON ctsk_ID = clog_ctsk_ID
				 WHERE clog_ctsk_ID IS NULL
					 AND ctsk_start_datetime <= ' . $DB->quote(date2mysql($localtimenow)) . '
				 ORDER BY ctsk_start_datetime ASC, ctsk_ID ASC
				 LIMIT 1';
$task = $DB->get_row($sql, OBJECT, 0, 'Get next task to run in queue which has not started execution yet');
$error_task = NULL;
if (empty($task)) {
    cron_log('There is no task to execute yet.', 0);
} else {
    $ctsk_ID = $task->ctsk_ID;
    $ctsk_name = cron_job_name($task->ctsk_key, $task->ctsk_name, $task->ctsk_params);
    cron_log('Requesting lock on task #' . $ctsk_ID . ' [' . $ctsk_name . ']', 0);
    $DB->halt_on_error = false;
    $DB->show_errors = false;
    $sql = 'INSERT INTO T_cron__log( clog_ctsk_ID, clog_realstart_datetime, clog_status)
					VALUES( ' . $ctsk_ID . ', ' . $DB->quote(date2mysql($localtimenow)) . ', "started" )';
    // Duplicate query for tests!
    // $DB->query( $sql, 'Request lock' );
    if ($DB->query($sql, 'Request lock') != 1) {
        // This has no affected exactly ONE row: error! (probably locked -- duplicate key -- by a concurrent process)
        $DB->show_errors = true;
        $DB->halt_on_error = true;
        cron_log('Could not lock. Task is probably handled by another process.', 2);
    } else {
        if (!empty($task->ctsk_repeat_after)) {
            // This task wants to be repeated: