diff --git a/db/builder_db.ml b/db/builder_db.ml index f0e1257..063aaa4 100644 --- a/db/builder_db.ml +++ b/db/builder_db.ml @@ -315,6 +315,19 @@ module Build = struct ORDER BY start_d DESC, start_ps DESC |} + (* XXX: caqti doesn't like this *) + let get_all_failed = + Caqti_request.collect + Caqti_type.(option string) + (Caqti_type.tup2 (id `build) t) + {| SELECT id, uuid, start_d, start_ps, finish_d, finish_ps, + result_code, result_msg, console, script, platform, + main_binary, input_id, user, job + FROM build + WHERE ?1 IS NULL OR ?1 = build.platform + ORDER BY start_d DESC, start_ps DESC + |} + let get_all_artifact_sha = Caqti_request.collect (id `job) diff --git a/db/builder_db.mli b/db/builder_db.mli index bae5eae..56bb2b9 100644 --- a/db/builder_db.mli +++ b/db/builder_db.mli @@ -113,6 +113,8 @@ sig Caqti_request.t val get_all : ([`job] id, [`build] id * t, [ `Many | `One | `Zero ]) Caqti_request.t + val get_all_failed : + (string option, [`build] id * t, [ `Many | `One | `Zero ]) Caqti_request.t val get_all_artifact_sha : ([`job] id, Cstruct.t, [ `Many | `One | `Zero ]) Caqti_request.t val get_all_artifact_sha_by_platform : diff --git a/lib/builder_web.ml b/lib/builder_web.ml index efcfb11..711b549 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -230,6 +230,15 @@ let add_routes datadir = Dream.respond ~headers data |> Lwt_result.ok in + let failed_builds req = + let platform = Dream.query "platform" req in + Dream.sql req (Model.failed_builds platform) + |> if_error "Error getting data" + ~log:(fun e -> Log.warn (fun m -> m "Error getting failed builds: %a" + pp_error e)) >>= fun builds -> + Views.failed_builds builds |> string_of_html |> Dream.html |> Lwt_result.ok + in + let upload req = let* body = Dream.body req in Builder.Asn.exec_of_cs (Cstruct.of_string body) |> Lwt.return @@ -369,6 +378,7 @@ let add_routes datadir = Dream.get "/job/:job/build/:build/main-binary" (w redirect_main_binary); Dream.get "/job/:job/build/:build/script" (w (job_build_static_file `Script)); Dream.get "/job/:job/build/:build/console" (w (job_build_static_file `Console)); + Dream.get "/failed-builds/" (w failed_builds); Dream.get "/hash" (w hash); Dream.get "/compare/:build_left/:build_right/" (w compare_builds); Dream.post "/upload" (Authorization.authenticate (w upload)); diff --git a/lib/model.ml b/lib/model.ml index c25e822..9a755be 100644 --- a/lib/model.ml +++ b/lib/model.ml @@ -81,6 +81,9 @@ let previous_successful_build_uuid id (module Db : CONN) = let next_successful_build_uuid id (module Db : CONN) = Db.find_opt Builder_db.Build.get_next_successful_uuid id +let failed_builds platform (module Db : CONN) = + Db.collect_list Builder_db.Build.get_all_failed platform >|= List.map snd + let builds_with_different_input_and_same_main_binary id (module Db : CONN) = Db.collect_list Builder_db.Build.get_different_input_same_output_input_ids id >>= fun ids -> Lwt_list.fold_left_s (fun acc input_id -> diff --git a/lib/model.mli b/lib/model.mli index 3a8ce8b..da7c712 100644 --- a/lib/model.mli +++ b/lib/model.mli @@ -45,6 +45,9 @@ val previous_successful_build_uuid : [`build] Builder_db.id -> Caqti_lwt.connect val next_successful_build_uuid : [`build] Builder_db.id -> Caqti_lwt.connection -> (Uuidm.t option, [> Caqti_error.call_or_retrieve ]) result Lwt.t +val failed_builds : string option -> Caqti_lwt.connection -> + (Builder_db.Build.t list, [> Caqti_error.call_or_retrieve ]) result Lwt.t + val builds_with_different_input_and_same_main_binary : [`build] Builder_db.id -> Caqti_lwt.connection -> (Builder_db.Build.t list, [> Caqti_error.call_or_retrieve ]) result Lwt.t diff --git a/lib/views.ml b/lib/views.ml index f4d911b..1d81aed 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -493,3 +493,13 @@ let compare_builds job_left job_right h3 ~a:[a_id "pkgs-changed"] [txt "System packages changed"]; code (key_value_changes changed_pkgs); ]) + +let failed_builds builds = + let build build = + let _ = build in + li [txt "build info here"] + in + layout ~title:"Failed builds" + ([ h1 [txt "Failed builds"]; + ul (List.map build builds) ]) +