open Whenutils
+open Big_int
open Unix
open Printf
);
(* Handle SIGCHLD to clean up jobs. *)
- Sys.set_signal Sys.sigchld (Sys.Signal_handle handle_sigchld)
+ Sys.set_signal Sys.sigchld (Sys.Signal_handle handle_sigchld);
+
+ (* Initialize the variables. XXX Eventually this will be saved
+ * and loaded from a persistent store.
+ *)
+ variables := StringMap.add "JOBSERIAL" (T_int zero_big_int) !variables
and proc_reload_file () =
if !debug then Syslog.notice "remote call: reload_file";
tm.tm_hour tm.tm_min tm.tm_sec
and run_job job =
- Syslog.notice "running %s" job.job_name;
+ let () =
+ (* Increment JOBSERIAL. *)
+ let serial =
+ match StringMap.find "JOBSERIAL" !variables with
+ | T_int serial ->
+ let serial = succ_big_int serial in
+ variables := StringMap.add "JOBSERIAL" (T_int serial) !variables;
+ serial
+ | _ -> assert false in
+
+ Syslog.notice "running %s (JOBSERIAL=%s)"
+ job.job_name (string_of_big_int serial) in
(* Create a temporary directory. The current directory of the job
* will be in this directory. The directory is removed when the
every 2 seconds :
<<
- echo $JOBNAME $counter >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME $counter >\> $HOME/test_output
whenjobs --set counter $(($counter+1)) --type int
>>
when counter = 3 :
<<
- echo $JOBNAME $counter >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME $counter >\> $HOME/test_output
whenjobs --daemon-stop
>>
-job$1
-job$1 1
-job$1 2
-job$2 3
+1 job$1
+2 job$1 1
+3 job$1 2
+4 job$2 3
every second :
<<
- echo $JOBNAME >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME >\> $HOME/test_output
whenjobs --set counter $(($counter+1)) --type int
>>
when counter < 5 && counter mod 2 == 0 :
<<
- echo $JOBNAME >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME >\> $HOME/test_output
>>
when counter < 5 && counter mod 2 == 1 :
<<
- echo $JOBNAME >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME >\> $HOME/test_output
>>
when counter == 5 :
<<
- echo $JOBNAME >\> $HOME/test_output
+ echo $JOBSERIAL $JOBNAME >\> $HOME/test_output
whenjobs --daemon-stop
>>
-job$1
-job$3
-job$1
-job$2
-job$1
-job$3
-job$1
-job$2
-job$1
-job$4
+1 job$1
+2 job$3
+3 job$1
+4 job$2
+5 job$1
+6 job$3
+7 job$1
+8 job$2
+9 job$1
+10 job$4
trap - INT TERM QUIT EXIT
rm -rf "$testdir/.whenjobs"
+# Sort the output by job serial number, so that jobs that happened to
+# fire off in parallel are still recorded in order.
+sort -n -o "$testdir/test_output" "$testdir/test_output"
+
# Check the test output matches the expected output.
if ! cmp -s "$testdir/test_output" "$1.expected"; then
echo "$0: $1: test output did not match expected output"