summaryrefslogtreecommitdiff
path: root/scire
diff options
context:
space:
mode:
authorPreston Cody <codeman@gentoo.org>2007-08-07 01:36:04 +0000
committerPreston Cody <codeman@gentoo.org>2007-08-07 01:36:04 +0000
commitd8fdb6acc366021b6997063044bde33efb457d3e (patch)
tree6edda2aeecc2e5944406f57f285acba65e919cb2 /scire
parenttrying to make dyn_tags work better (diff)
downloadscire-d8fdb6acc366021b6997063044bde33efb457d3e.tar.gz
scire-d8fdb6acc366021b6997063044bde33efb457d3e.tar.bz2
scire-d8fdb6acc366021b6997063044bde33efb457d3e.zip
This is a very large commit from Rodrigo Lazo (rlazo) for Google SoC
This is the latest patch on the job execution series. As far as I could test it, now scire should be able to create, distribute, execute and gather the output of a job with the new models. Also the jobs register their status on the database (pending, downloaded, running, failed, finished or cancelled). So now all the backend code needed to "watch" a job is on its place. Right now a job gets executed but dies on the post processing stage (at least that is what I understand from the error message) Just move the GACL_functions.py from server/ to server/modules and apply this patch and you'll how myltiple entries are created for each member of the group in jobs_clients and on job_history. I've take some precautions regarding concurrency adding some locks, I'm not sure they are enough so please comment on that svn path=/; revision=247
Diffstat (limited to 'scire')
-rwxr-xr-xscire/.lib/DB_functions.php52
-rw-r--r--scire/add_job.php4
2 files changed, 51 insertions, 5 deletions
diff --git a/scire/.lib/DB_functions.php b/scire/.lib/DB_functions.php
index 66b7079..a84cb33 100755
--- a/scire/.lib/DB_functions.php
+++ b/scire/.lib/DB_functions.php
@@ -353,14 +353,37 @@ function scire_add_job($script, $priority, $creator, $permission, $description,
if (!$result) {
return $db->error;
}
- $result = $db->insert('job_conditions', array('jobid' => $jobid, 'job_dependency' => $job_dependency, 'run_schedule' => $run_schedule, 'validity_period' => $validity_period));
+
+ if ($run_schedule != "") {
+ $cron = new CronParser($run_schedule);
+ $nextRun = $cron->calculateNextRun();
+ var_dump($nextRun);
+ $nextRun = mktime( $nextRun[1], $nextRun[0], 0, $nextRun[3], $nextRun[2], $nextRun[4] );
+ $expTime = $nextRun + ( $validity_period * 60);
+ $nextRun = strftime( '%Y-%m-%d %T', $nextRun );
+ $expTime = strftime( '%Y-%m-%d %T', $expTime );
+ } else {
+ $nextRun = "";
+ $expTime = "";
+ }
+ # Add conditions
+ $result = $db->insert('job_conditions', array('jobid' => $jobid, 'job_dependency' => $job_dependency, 'run_schedule' => $run_schedule, 'deploy_time' => $nextRun, 'expiration_time' => $expTime, 'validity_period' => $validity_period));
if (!$result) {
return $db->error;
}
-
+
+ # Add history entry only if the job is assigned to a specific
+ # client. Managing groups require a different approach
#Now add the clients.
+ $status = get_statusid('Pending');
if ($clients) {
foreach ($clients as $client) {
+ $result = $db->insert('job_history', array('jobid' => $jobid, 'clientid' => $client,
+ 'statusid' => $status,
+ 'eventmsg' => 'Job created'));
+ if (!$result) {
+ return $db->error;
+ }
$result = $db->insert('jobs_clients', array('jobid' => $jobid, 'clientid' => $client));
if (!$result) {
return $db->error;
@@ -450,6 +473,20 @@ function scire_edit_job($jobid, $fields) {
}
}
+function get_statusid($statusname) {
+ global $db;
+ $name = htmlentities($statusname);
+ $result = $db->select('SELECT statusid FROM jobs_status WHERE statusname = \'' . $name . '\'');
+
+ if ($result) {
+ var_dump( $result[0]['statusid'] );
+
+ return $result[0]['statusid'];
+ }
+ else {
+ return $db->error;
+ }
+}
function scire_add_script($name, $desc, $location, $script_data, $log_location, $success_code, $run_as, $priority, $permission, $pp_location, $pp_script_data, $script_tags) {
global $db;
@@ -473,7 +510,16 @@ function scire_add_script($name, $desc, $location, $script_data, $log_location,
return 0; #Success
}
-
+function get_dyn_tag_value($scriptid,$tag) {
+ global $db;
+ $scriptid = (int) $scriptid;
+ $result = $db->select('tag_value', 'dyn_tags', "`scriptid` = $scriptid AND `tag` = '$tag'");
+ if ($result && count($result) > 0) {
+ return $result[0]['tag_value'];
+ } else {
+ return false;
+ }
+}
diff --git a/scire/add_job.php b/scire/add_job.php
index 37499ca..140f83d 100644
--- a/scire/add_job.php
+++ b/scire/add_job.php
@@ -39,7 +39,8 @@ if ($_POST['ADD']) {
$scheduleComplete = $_POST["minute1"] and $_POST["hour1"] and
$_POST["day1"] and $_POST["month1"] and $_POST["weekday1"];
if ($scheduleComplete) {
- $str = implode(" ", array($_POST["minute1"], $_POST["hour1"],$_POST["day1"], $_POST["month1"], $_POST["weekday1"]));
+ $str = implode(" ", array($_POST["minute1"], $_POST["hour1"],
+ $_POST["day1"], $_POST["month1"], $_POST["weekday1"]));
} else {
$str = "";
}
@@ -47,7 +48,6 @@ if ($_POST['ADD']) {
$dependency = 1;
try {
- #$cron = new CronParser($str);
$result = scire_add_job($_POST['script'], $priority, $_SESSION['userid'], $permission, $description, $pending, $_POST['clients'], $_POST['clientgroups'], $dependency, $str, $_POST['validity_period']);
if (!$result) {