2020-12-02 13:33:15 +00:00
|
|
|
let src = Logs.Src.create "builder-web.model" ~doc:"Builder_web model"
|
|
|
|
module Log = (val Logs.src_log src : Logs.LOG)
|
|
|
|
|
|
|
|
open Rresult.R.Infix
|
|
|
|
|
|
|
|
type t = {
|
|
|
|
dir : Fpath.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
type job = {
|
2020-12-07 09:17:49 +00:00
|
|
|
path : Fpath.t;
|
|
|
|
runs : Fpath.t list;
|
2020-12-02 13:33:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:17:49 +00:00
|
|
|
let job_name { path; _ } = Fpath.to_string path
|
2020-12-02 13:33:15 +00:00
|
|
|
|
|
|
|
type job_run_info = {
|
|
|
|
job_info : Builder.job;
|
|
|
|
uuid : Uuidm.t;
|
|
|
|
out : (int * string) list;
|
|
|
|
start : Ptime.t;
|
|
|
|
finish : Ptime.t;
|
|
|
|
result : Builder.execution_result;
|
|
|
|
data : (Fpath.t * string) list
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:17:49 +00:00
|
|
|
let read_full t path run =
|
|
|
|
let f = Fpath.(t.dir // path // run / "full") in
|
2020-12-02 13:33:15 +00:00
|
|
|
Bos.OS.File.read f >>= fun s ->
|
|
|
|
Builder.Asn.exec_of_cs (Cstruct.of_string s)
|
|
|
|
>>| fun (job_info, uuid, out, start, finish, result, data) ->
|
|
|
|
{ job_info; uuid; out; start; finish; result; data }
|
|
|
|
|
2020-12-07 09:17:49 +00:00
|
|
|
let job t job =
|
2020-12-02 13:33:15 +00:00
|
|
|
Bos.OS.Dir.contents ~rel:true Fpath.(t.dir // job) >>= fun job_runs ->
|
2020-12-07 09:17:49 +00:00
|
|
|
Ok { path = job; runs = job_runs }
|
2020-12-02 13:33:15 +00:00
|
|
|
|
|
|
|
let jobs t =
|
|
|
|
Bos.OS.Dir.contents ~rel:true t.dir >>|
|
|
|
|
List.filter (fun f -> not (Fpath.equal (Fpath.v "state") f)) >>|
|
2020-12-07 09:17:49 +00:00
|
|
|
List.filter_map (fun f ->
|
|
|
|
match job t f with
|
2020-12-02 13:33:15 +00:00
|
|
|
| Ok job -> Some job
|
|
|
|
| Error (`Msg e) ->
|
2020-12-07 09:17:49 +00:00
|
|
|
Log.warn (fun m -> m "Error reading job run dir %a: %s" Fpath.pp
|
|
|
|
Fpath.(t.dir // f) e);
|
2020-12-02 13:33:15 +00:00
|
|
|
None)
|