Code

new funktionality: periodical jobs
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 29 Jun 2009 11:13:16 +0000 (11:13 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 29 Jun 2009 11:13:16 +0000 (11:13 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13817 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/modules/GosaPackages.pm
gosa-si/tests/client.php

index 8e7f37918bb0331802da5a19d64f2114f7c1e6e5..46d9fbbf2de00aa8c2fbabc8340bc42f2efa505d 100755 (executable)
@@ -1712,26 +1712,28 @@ sub watch_for_done_jobs {
 
        while( my ($number, $hit) = each %{$res} ) 
        {
+               # Non periodical jobs can be deleted.
+               if ($hit->{periodic} eq "none")
+               {
+                       my $jobdb_id = $hit->{id};
+                       my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
+                       my $res = $job_db->del_dbentry($sql_statement); 
+               }
+
                # Periodical jobs should not be deleted but reactivated with new timestamp instead.
-               if (exists $check_periodic->{$hit->{periodic}})
+               else
                {
+                       my ($p_time, $periodic) = split("_", $hit->{periodic});
                        my $reactivated_ts = $hit->{timestamp};
                        my $act_ts = int(&get_time());
                        while ($act_ts > int($reactivated_ts))   # Redo calculation to avoid multiple jobs in the past
                        {
-                               $reactivated_ts = &calc_timestamp($reactivated_ts, "plus", 1, $hit->{periodic});
+                               $reactivated_ts = &calc_timestamp($reactivated_ts, "plus", $p_time, $periodic);
                        }
                        my $sql = "UPDATE $job_queue_tn SET status='waiting', timestamp='$reactivated_ts' WHERE id='".$hit->{id}."'"; 
                        my $res = $job_db->exec_statement($sql);
                        &daemon_log("J INFO: Update periodical job '".$hit->{headertag}."' for client '".$hit->{targettag}."'. New execution time '$reactivated_ts'.", 5);
                }
-               # Non periodical jobs can be deleted.
-               else
-               {
-                       my $jobdb_id = $hit->{id};
-                       my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
-                       my $res = $job_db->del_dbentry($sql_statement); 
-               }
        }
 
        $kernel->delay_set('watch_for_done_jobs',$job_queue_loop_delay);
index 88b2910086b47a587154458d62354b749025686f..60ee896db11f140fbf7dfbf06ec6ba3e27a76940 100644 (file)
@@ -280,6 +280,7 @@ sub process_job_msg {
        
     # Check if it is a periodical job
     my $periodic = 'none';
+    my $periodic_time = 1;
     if (exists $msg_hash->{periodic})
     {
         $periodic = $msg_hash->{periodic}[0];
@@ -299,6 +300,34 @@ sub process_job_msg {
                 "</xml>";
             return ($out_msg);
         }
+
+        if (exists $msg_hash->{$periodic})   # Check periodical time tag and set value
+        {
+            if (ref $msg_hash->{$periodic}[0] eq "HASH")   # Periodical time tag is empty
+            {
+                &main::daemon_log("$session_id ERROR: Message contains no content of periodical time tag.".
+                        " Please use an integer for this tag (i. e.: <periodic>hours</periodoc><hours>5</hours>)", 1);
+                $out_msg = "<xml>".
+                    "<header>answer</header><source>$main::server_address</source><target>GOSA</target>".
+                    "<answer1>1</answer1><error_string>Message contains no content of periodic time tag</error_string>".
+                    "</xml>";
+                return ($out_msg);
+
+            }
+
+            if (not $msg_hash->{$periodic}[0] =~ /[1-9]+\d*/)   # Periodical time tag is not an INT > 0
+            {
+                &main::daemon_log("$session_id ERROR: Message contains invalid periodical time tag '$msg_hash->{$periodic}[0]'.".
+                        " Please use an integer for this tag (i. e.: <periodic>hours</periodoc><hours>5</hours>)", 1);
+                $out_msg = "<xml>".
+                    "<header>answer</header><source>$main::server_address</source><target>GOSA</target>".
+                    "<answer1>1</answer1><error_string>Message contains invalid periodic time tag '$msg_hash->{$periodic}[0]'</error_string>".
+                    "</xml>";
+                return ($out_msg);
+            }
+
+            $periodic_time = $msg_hash->{$periodic}[0];
+        }
     }
 
     # Add job to job queue
@@ -316,7 +345,7 @@ sub process_job_msg {
                        plainname=>$plain_name,
             siserver=>"localhost",
             modified=>"1",
-            periodic=>$periodic,
+            periodic=>$periodic_time."_".$periodic,
         };
         my $res = $main::job_db->add_dbentry($func_dic);
         if (not $res == 0) {
index cad44ef304f8ca0c8caf7eb9a3b2868f6e0712e5..9b9bdcfe2dc5028174b4ca413ad84d3308c4f6c1 100755 (executable)
@@ -19,7 +19,7 @@ for($count = 1; $count <= $zahl; $count++)
        ##############################
        # periodical jobs
        $data = "<xml><header>job_trigger_action_reboot</header><source>GOSA</source><target>00:0c:29:4c:4b:0c</target><macaddress>00:0c:29:4c:4b:0c</macaddress><timestamp>20090622000000</timestamp><periodic>minutes</periodic></xml>"; 
-
+       $data = "<xml><header>job_trigger_action_reboot</header><source>GOSA</source><target>00:0c:29:4c:4b:0c</target><timestamp>20090626135000</timestamp><macaddress>00:0c:29:4c:4b:0c</macaddress><periodic>minutes</periodic><minutes>5</minutes></xml>";
     /* Prepare a hunge bunch of data to be send */
     # jobdb add
     #$data = "<xml> <header>gosa_network_completition</header> <source>GOSA</source><target>GOSA</target><hostname>ws-muc-2</hostname></xml>";