update git repo and fetch archives hourly

This commit is contained in:
Hannes Mehnert 2022-09-26 14:11:23 +02:00
parent 44d737887a
commit 0cf002e0cd

View file

@ -501,10 +501,7 @@ stamp: %S
Logs.info (fun f -> f "requested %s" request.Httpaf.Request.target); Logs.info (fun f -> f "requested %s" request.Httpaf.Request.target);
match String.split_on_char '/' request.Httpaf.Request.target with match String.split_on_char '/' request.Httpaf.Request.target with
| [ ""; x ] when String.equal x hook_url -> | [ ""; x ] when String.equal x hook_url ->
Lwt.async (fun () -> Lwt.async update;
update_git t git_kv >>= function
| None -> Lwt.return_unit
| Some store -> update store);
let data = "Update in progress" in let data = "Update in progress" in
let mime_type = "text/plain" in let mime_type = "text/plain" in
let headers = [ let headers = [
@ -644,7 +641,11 @@ stamp: %S
Logs.info (fun m -> m "git: %s" commit_id); Logs.info (fun m -> m "git: %s" commit_id);
Serve.create git_kv >>= fun serve -> Serve.create git_kv >>= fun serve ->
Paf.init ~port:(Key_gen.port ()) (Stack.tcp stack) >>= fun t -> Paf.init ~port:(Key_gen.port ()) (Stack.tcp stack) >>= fun t ->
let update _changes = download_archives disk http_ctx git_kv in let update () =
Serve.update_git serve git_kv >>= function
| None -> Lwt.return_unit
| Some _changes -> download_archives disk http_ctx git_kv
in
let service = let service =
Paf.http_service Paf.http_service
~error_handler:(fun _ ?request:_ _ _ -> ()) ~error_handler:(fun _ ?request:_ _ _ -> ())
@ -652,6 +653,13 @@ stamp: %S
in in
let `Initialized th = Paf.serve service t in let `Initialized th = Paf.serve service t in
Logs.info (fun f -> f "listening on %d/HTTP" (Key_gen.port ())); Logs.info (fun f -> f "listening on %d/HTTP" (Key_gen.port ()));
Lwt.async (fun () ->
let rec go () =
Time.sleep_ns (Duration.of_hour 1) >>= fun () ->
update () >>= fun () ->
go ()
in
go ());
download_archives disk http_ctx git_kv >>= fun () -> download_archives disk http_ctx git_kv >>= fun () ->
(th >|= fun _v -> ()) (th >|= fun _v -> ())
end end