From c2b755233d28ccc6808a37247c4d2597960f3771 Mon Sep 17 00:00:00 2001 From: hecht Date: Wed, 1 Feb 2012 17:40:13 +0000 Subject: [PATCH] added support for tasking ;) --- ag/include/semaphore.inc.php | 6 +++++- ag/include/tasking.inc.php | 29 +++++++++++++++++++++++++---- db/animegame_svn.sql | 13 +++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/ag/include/semaphore.inc.php b/ag/include/semaphore.inc.php index 4201e92..b645513 100644 --- a/ag/include/semaphore.inc.php +++ b/ag/include/semaphore.inc.php @@ -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.')
' . PHP_EOL ; if($GLOBALS['semaphorecount'] == 0){ ignore_user_abort(true); // Verarbeitung darf NICHT abgebrochen werden!! diff --git a/ag/include/tasking.inc.php b/ag/include/tasking.inc.php index a3e32b7..b1e4f95 100644 --- a/ag/include/tasking.inc.php +++ b/ag/include/tasking.inc.php @@ -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']) diff --git a/db/animegame_svn.sql b/db/animegame_svn.sql index bae5ba7..3fbb40e 100644 --- a/db/animegame_svn.sql +++ b/db/animegame_svn.sql @@ -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 */;