Files
Testing/batemin/semods_scheduler.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

100 lines
2.4 KiB
PHP

<?php
// GET TO GROUND LEVEL
chdir( dirname(__FILE__) );
if(!isset($_SERVER['HTTP_REQUEST'])) {
// SIMULATE APACHE ENVIRONMENT FOR SAUCY FUNCTIONS
@include '../include/scheduler_config.php';
if(!isset($scheduler_http_host) || $scheduler_http_host == '') {
@include_once '../include/database_config.php';
$scheduler_database_connection = mysql_connect($database_host, $database_username, $database_password);
@mysql_select_db($database_name, $scheduler_database_connection);
$scheduler_database_result = mysql_query("SELECT setting_scheduler_http_host, setting_scheduler_http_port, setting_scheduler_php_self FROM se_semods_settings", $scheduler_database_connection);
$scheduler_settings = mysql_fetch_assoc($scheduler_database_result);
$scheduler_http_host = $scheduler_settings['setting_scheduler_http_host'];
$scheduler_http_port = $scheduler_settings['setting_scheduler_http_port'];
$scheduler_php_self = $scheduler_settings['setting_scheduler_php_self'];
}
$_SERVER['HTTP_HOST'] = $scheduler_http_host;
$_SERVER['HTTP_PORT'] = $scheduler_http_port;
$_SERVER['PHP_SELF'] = $scheduler_php_self;
}
$page = "admin_login";
include "admin_header.php";
include_once "../include/functions_scheduler.php";
// SET ERROR REPORTING
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
// TBD: reentrancy?
// PROCESS ALL QUEUED TASKS
$processed_tasks = array();
for(;;) {
$task = semods::db_query_assoc('SELECT * FROM se_semods_jobs WHERE job_enabled = 1 AND ( UNIX_TIMESTAMP( NOW() ) - job_lastrun >= job_period ) ORDER BY job_id ASC LIMIT 1');
// No more tasks
if($task === false)
break;
$task_processed = false;
// Mark it as run
$database->database_query("UPDATE se_semods_jobs SET job_lastrun = UNIX_TIMESTAMP( NOW() ) WHERE job_id = {$task['job_id']}");
switch($task['job_type']) {
// function call
case 0:
if(is_callable($task['job_command'])) {
call_user_func( $task['job_command'], $task['job_metadata'] );
}
$task_processed = true;
break;
// file - must be absolute
// how this can be protected from fatal errors?
case 1:
if(file_exists($task['job_command'])) {
include $task['job_command'];
}
$task_processed = true;
break;
// url
case 2:
scheduler_exec_url( $task['job_command'], $task['job_metadata'] );
$task_processed = true;
break;
}
}
scheduler_send_log();
exit();
?>