<dt><?php echo _('Aktiv'); ?> </dt> <dd><?php echo $schedule->active ? _('Ja') : _('Nein'); ?> </dd> <dt><?php echo _('Priorität'); ?> </dt> <dd><?php echo CronjobSchedule::describePriority($schedule->priority); ?> </dd> <? if (count($schedule->parameters) > 0): ?> <dt><?php echo _('Parameter'); ?> </dt> <dd> <ul> <? foreach ($schedule->parameters as $parameter): ?> <li><?php echo htmlReady($parameter); ?> </li>
/** * Sets the filters for the log view. * Filters are stored in the session. */ public function filter_action() { $filter = array_filter(Request::optionArray('filter')); $conditions = array(); if (!empty($filter['status'])) { $conditions[] = ($filter['status'] === 'passed') ? "exception = 'N;'" : "exception != 'N;'"; } if (!empty($filter['schedule_id'])) { $conditions[] = "schedule_id = " . DBManager::get()->quote($filter['schedule_id']); } if (!empty($filter['task_id'])) { $temp = CronjobSchedule::findByTask_id($filter['task_id']); $temp = SimpleORMapCollection::createFromArray($temp); $schedule_ids = $temp->pluck('schedule_id') ?: null; $conditions[] = "schedule_id IN (" . DBManager::get()->quote($schedule_ids). ")"; } $_SESSION['cronlog-filter'] = array( 'where' => implode(" AND " , $conditions) ?: '1', 'values' => $filter, ); $this->redirect('admin/cronjobs/logs'); }
/** * Runs a schedule and returns the output. * * @param String $id Id of the schedule */ public function testrun_action($id) { error_reporting(22519); set_error_handler(function ($fehlercode, $fehlertext, $fehlerdatei, $fehlerzeile) { switch ($fehlercode) { case E_USER_ERROR: echo "ERROR: " . $fehlertext . "\n in " . $fehlerdatei . " , " . $fehlerzeile; die; break; case E_USER_WARNING: echo "WARNING: " . $fehlertext . "\n in " . $fehlerdatei . " , " . $fehlerzeile; die; break; } }); $result = CronjobSchedule::find($id)->execute(true); var_dump($result); $this->render_nothing(); }
/** * Executes the available schedules if they are to be executed. * This method can only be run once - even if one execution takes more * than planned. This is ensured by a locking mechanism. */ public function run() { if (!Config::get()->CRONJOBS_ENABLE) { return; } $escalation_time = Config::get()->CRONJOBS_ESCALATION; // Check whether a previous cronjob worker is still running. if ($this->lock->isLocked($data)) { // Running but not yet escalated -> let it run if ($data['timestamp'] + $escalation_time > time()) { return; } // Load locked schedule $schedule = CronjobSchedule::find($data['schedule_id']); // If we discovered a deadlock release it if ($schedule) { // Deactivate schedule $schedule->deactivate(); // Adjust log $log = CronjobLog::find($data['log_id']); $log->duration = time() - $data['timestamp']; $log->exception = new Exception('Cronjob has escalated'); $log->store(); // Inform roots about the escalated cronjob $subject = sprintf('[Cronjobs] %s: %s', _('Eskalierte Ausführung'), $schedule->title); $message = sprintf(_('Der Cronjob "%s" wurde deaktiviert, da ' . 'seine Ausführungsdauer die maximale ' . 'Ausführungszeit von %u Sekunden ' . 'überschritten hat.') . "\n", $schedule->title, $escalation_time); $this->sendMailToRoots($subject, $message); } // Release lock $this->lock->release(); } // Find all schedules that are due to execute and which task is active $temp = CronjobSchedule::findBySQL('active = 1 AND next_execution <= UNIX_TIMESTAMP() ' . 'ORDER BY priority DESC, next_execution ASC'); # $temp = SimpleORMapCollection::createFromArray($temp); $schedules = array_filter($temp, function ($schedule) { return $schedule->task->active; }); if (count($schedules) === 0) { return; } foreach ($schedules as $schedule) { $log = new CronjobLog(); $log->schedule_id = $schedule->schedule_id; $log->scheduled = $schedule->next_execution; $log->executed = time(); $log->exception = null; $log->duration = -1; $log->store(); set_time_limit($escalation_time); // Activate the file lock and store the current timestamp, // schedule id and according log id in it $this->lock->lock(array('schedule_id' => $schedule->schedule_id, 'log_id' => $log->log_id)); // Start capturing output and measuring duration ob_start(); $start_time = microtime(true); try { $schedule->execute(); } catch (Exception $e) { $log->exception = $e; // Deactivate schedule $schedule->deactivate(); // Send mail to root accounts $subject = sprintf('[Cronjobs] %s: %s', _('Fehlerhafte Ausführung'), $schedule->title); $message = sprintf(_('Der Cronjob "%s" wurde deaktiviert, da bei der Ausführung ein Fehler aufgetreten ist.'), $schedule->title) . "\n"; $message .= "\n"; $message .= display_exception($e) . "\n"; $message .= _('Für weiterführende Informationen klicken Sie bitten den folgenden Link:') . "\n"; $message .= $GLOBALS['ABSOLUTE_URI_STUDIP'] . URLHelper::getURL('dispatch.php/admin/cronjobs/logs/schedule/' . $schedule->schedule_id); $this->sendMailToRoots($subject, $message); } // Actually capture output and duration $end_time = microtime(true); $output = ob_get_clean(); // Complete log $log->output = $output; $log->duration = $end_time - $start_time; $log->store(); } // Release lock $this->lock->release(); }
<td> <input type="hidden" name="active" value="0"> <input type="checkbox" name="active" id="active" value="1" <? if ($schedule->active) echo 'checked'; ?>> </td> </tr> <tr> <td> <label for="priority"><?php echo _('Priorität'); ?> </label> </td> <td> <select name="priority" id="priority"> <? foreach (CronjobSchedule::getPriorities() as $priority => $label): ?> <option value="<?php echo $priority; ?> " <? if ((!$schedule->priority && $priority === CronjobSchedule::PRIORITY_NORMAL) || $schedule->priority === $priority) echo 'selected'; ?>> <?php echo htmlReady($label); ?> </option> <? endforeach; ?> </select> </td> </tr> <tr> <td> <label for="title"><?php