+and cleanup_job job dir status =
+ (* If there is a cleanup function, run it. *)
+ (match job.job_cleanup with
+ | None -> ()
+ | Some cleanup ->
+ let code =
+ match status with
+ | WEXITED c -> c
+ | WSIGNALED s | WSTOPPED s -> 1 in
+ let result = {
+ res_job_name = job.job_name;
+ res_code = code;
+ res_tmpdir = dir;
+ res_output = dir // "output.txt"
+ } in
+ try cleanup result
+ with
+ | Failure msg ->
+ Syslog.error "job %s cleanup function failed: %s" job.job_name msg
+ | exn ->
+ Syslog.error "job %s cleanup function exception: %s"
+ job.job_name (Printexc.to_string exn)
+ );
+