added support for tasking ;)

main
hecht 13 years ago
parent 8ebfd29da0
commit c2b755233d

@ -30,7 +30,11 @@
$GLOBALS['semaphorecount'] = 0;
function semaphoreUP($ressource){
/**
* Tries to grab the semaphore
* @param string $resource the name of the resource
*/
function semaphoreUP($resource){
// echo 'semaphoreUp('.$ressource.')<br>' . PHP_EOL ;
if($GLOBALS['semaphorecount'] == 0){
ignore_user_abort(true); // Verarbeitung darf NICHT abgebrochen werden!!

@ -7,6 +7,7 @@
*/
include_once(ROOT_PATH.'/include/semaphore.inc.php');
include_once(ROOT_PATH.'/include/define.inc.php');
include_once(ROOT_PATH . '/include/sqlwrapper.inc.php');
define(TASKING_NO_RESCEDULE, 0);
@ -21,6 +22,8 @@ define(TASKING_12_HOUR, 8);
define(TASKING_DAYLY, 9);
define(TASKING_DAY_OF_WEEK, 10);
define(TASKING_DAY_OF_MONTH, 11);
defineIfNotDefined('TASKING_CRONJOB_PATH', '', true); // does not have to be set when having crond-support ;)
/**
* The method that has to be called by a cronjob!
@ -51,11 +54,19 @@ function tick() {
* @param int $task_id the task id that should be updated (if one only wants to update an existant job)
*/
function schedule($script_name, array $parameters, $execution_time, $repeat_mode, $catchUpOn = false, $task_id = NULL) {
// FIXME: Solve the parameter problem differently ;)
// FIXME: Solve the parameter problem differently
// as it is not yet clear how to start a multi command transaction do it the dirty way here and solve it in the right way later
// so please do not hate me Jester and don't tell my mum ;)
$parameters_string = '';
foreach($parameters as $key => $value){
$parameters_string .= $key .'='.$value.' ';
}
if($task_id === NULL) {
db_query('INSERT INTO tasking(script_name, parameter, schedule_time, mode, catchup) values(\''.$script_name.'\', \''.implode(',', $parameters).'\', \''.$execution_time.'\', \''.$repeat_mode.'\', \''.$catchUpOn.'\')');
db_query('INSERT INTO tasking(script_name, parameter, schedule_time, mode, catchup) values(\''.$script_name.'\', \''.$parameters_string.'\', \''.$execution_time.'\', \''.$repeat_mode.'\', \''.$catchUpOn.'\')');
} else {
db_query('UPDATE tasking SET script_name = \''.$script_name.'\' , parameter = \''.implode(',', $parameters).'\', schedule_time = \''.$execution_time.'\', mode = \''.$repeat_mode.'\', catchup = \''.$catchUpOn.'\' WHERE task_id = ' . $task_id);
db_query('UPDATE tasking SET script_name = \''.$script_name.'\' , parameter = \''.$parameters_string.'\', schedule_time = \''.$execution_time.'\', mode = \''.$repeat_mode.'\', catchup = \''.$catchUpOn.'\' WHERE task_id = ' . $task_id);
}
}
@ -118,7 +129,17 @@ function executeScript($task_id) {
return;
}
// TODO: execute the script
$path = null;
if(TASKING_CRONJOB_PATH != '') {
$path = TASKING_CRONJOB_PATH;
} else {
$path = ROOT_PATH;
}
exec('php5 ' . $path . '/' . $task['script_name'] . ' ' . $task['parameters'], $ausgabe);
if($ausgabe != NULL && $ausgabe != '') {
echo $ausgabe;
}
$time = $task['schedule_time'];
switch($task['mode'])

@ -1866,6 +1866,19 @@ CREATE TABLE `wochen_ware` (
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `tasking` (
`task_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`script_name` varchar(15) NOT NULL,
`parameter` varchar(255) NOT NULL,
`schedule_time` INTEGER UNSIGNED NOT NULL,
`mode` SMALLINT UNSIGNED NOT NULL,
`catchup` BOOLEAN NOT NULL,
PRIMARY KEY (`task_id`)
)
ENGINE = InnoDB
CHARACTER SET utf8 COLLATE utf8_general_ci;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

Loading…
Cancel
Save