A fork of mtelver's day10 project
1(** Read active build/doc/tool locks from day10's cache directory. *)
2
3type stage = Build | Doc | Tool
4
5type active_lock = {
6 stage : stage;
7 package : string;
8 version : string;
9 universe : string option; (* For Build/Doc: dependency hash. For Tool: OCaml version if applicable *)
10 pid : int;
11 start_time : float;
12 duration : float; (* seconds since start *)
13 layer_name : string option; (* Final layer directory name *)
14 temp_log_path : string option; (* Temp log path for live viewing *)
15}
16
17(** Convert library lock record to web-friendly format *)
18let of_lib_lock (lock : Day10_lib.Build_lock.lock_info) =
19 let now = Unix.time () in
20 let stage = match lock.stage with
21 | Day10_lib.Build_lock.Build -> Build
22 | Day10_lib.Build_lock.Doc -> Doc
23 | Day10_lib.Build_lock.Tool -> Tool
24 in
25 {
26 stage;
27 package = lock.package;
28 version = lock.version;
29 universe = lock.universe;
30 pid = lock.pid;
31 start_time = lock.start_time;
32 duration = now -. lock.start_time;
33 layer_name = lock.layer_name;
34 temp_log_path = lock.temp_log_path;
35 }
36
37let list_active_locks ~cache_dir =
38 Day10_lib.Build_lock.list_active ~cache_dir
39 |> List.map of_lib_lock
40
41let has_active_locks ~cache_dir =
42 match Day10_lib.Build_lock.list_active ~cache_dir with
43 | [] -> false
44 | _ -> true
45
46let format_duration seconds =
47 let seconds = int_of_float seconds in
48 if seconds < 60 then Printf.sprintf "%ds" seconds
49 else if seconds < 3600 then Printf.sprintf "%dm%ds" (seconds / 60) (seconds mod 60)
50 else Printf.sprintf "%dh%dm" (seconds / 3600) ((seconds mod 3600) / 60)