Commit c84c5ec0 authored by Fardale's avatar Fardale

update ocamlformat

parent 7e9cb37f
......@@ -9,13 +9,18 @@ let jobs : computation CCDeque.t = CCDeque.create ()
let jobs_id = ref 0
let string_of_ret_code = function
| `WEXITED i -> Printf.sprintf "WEXITED %i" i
| `WSIGNALED s -> Printf.sprintf "WSIGNALED %i" s
| `WSTOPPED s -> Printf.sprintf "WSTOPPED %i" s
| `WEXITED i ->
Printf.sprintf "WEXITED %i" i
| `WSIGNALED s ->
Printf.sprintf "WSIGNALED %i" s
| `WSTOPPED s ->
Printf.sprintf "WSTOPPED %i" s
let string_of_sockaddr = function
| Unix.ADDR_UNIX s -> s
| Unix.ADDR_INET (ip, _) -> Unix.string_of_inet_addr ip
| Unix.ADDR_UNIX s ->
s
| Unix.ADDR_INET (ip, _) ->
Unix.string_of_inet_addr ip
let end_job id sockaddr =
let n, l = SHashtbl.find nodes (string_of_sockaddr sockaddr) in
......@@ -34,7 +39,8 @@ let rec launch_job () =
SHashtbl.fold
(fun k (n, l) node ->
match node with
| Some x -> Some x
| Some x ->
Some x
| None ->
if n.cpu >= j.cpu && n.ram >= j.ram then Some (k, n, l) else None
)
......@@ -50,14 +56,15 @@ let rec launch_job () =
SHashtbl.replace nodes k
({n with cpu= n.cpu - j.cpu; ram= n.ram - j.ram}, j :: l) ;
Logs_lwt.debug (fun m ->
m "Send computation %i,%i to %s on %i" (fst j.id) (snd j.id)
n.addr n.port )
m "Send computation %i,%i to %s on %i" (fst j.id) (snd j.id) n.addr
n.port )
>>= fun () ->
Lwt_io.with_connection sockaddr (fun (_ic, oc) ->
Lwt_io.write oc (Serialization_j.string_of_query (`COMPUTATION j))
)
(* TODO: check return value *)
>>= Lwt.pause >>= launch_job )
>>= Lwt.pause
>>= launch_job )
else Logs_lwt.debug (fun m -> m "No compuatiton")
let server_handler pass port sockaddr (ic, _oc) =
......@@ -129,7 +136,8 @@ let server_handler pass port sockaddr (ic, _oc) =
(*Lwt_io.write oc "Wrong password"
<&>*)
Logs_lwt.warn (fun m -> m "Wrong password: %s" submission.pass)
| _ -> Logs_lwt.warn (fun m -> m "Receive a unwanted command") )
| _ ->
Logs_lwt.warn (fun m -> m "Receive a unwanted command") )
| Result.Error e ->
Logs_lwt.err (fun m ->
m "Error during the reception of the computation: %s"
......
......@@ -4,9 +4,12 @@ open Serialization_t
let max_std = 5120000 (* 5Mo *)
let process_status_to_ret_code = function
| Unix.WEXITED c -> `WEXITED c
| Unix.WSIGNALED s -> `WSIGNALED s
| Unix.WSTOPPED s -> `WSTOPPED s
| Unix.WEXITED c ->
`WEXITED c
| Unix.WSIGNALED s ->
`WSIGNALED s
| Unix.WSTOPPED s ->
`WSTOPPED s
let run_computation (computation : computation) =
Lwt_io.with_temp_file ~prefix:"ocluster" ~perm:0o700 (fun (name, oc) ->
......@@ -43,8 +46,10 @@ let handle_computation sockaddr computation () =
>>= fun result ->
let sockaddr =
match sockaddr with
| Unix.ADDR_INET (a, _) -> Unix.ADDR_INET (a, computation.port)
| s -> s
| Unix.ADDR_INET (a, _) ->
Unix.ADDR_INET (a, computation.port)
| s ->
s
in
Lwt_io.with_connection sockaddr (fun (_ic, oc) ->
Lwt_io.write oc (Serialization_j.string_of_query (`RESULT result)) )
......@@ -69,8 +74,10 @@ let server_handler pass sockaddr (ic, oc) =
{computation with env= []; script= "<script>"}) )
>|= fun () -> Lwt.async (handle_computation sockaddr computation)
else Logs_lwt.warn (fun m -> m "Wrong password: %s" computation.pass)
| `STAT -> stat oc <&> Logs_lwt.debug (fun m -> m "Receive a stat command")
| _ -> Logs_lwt.warn (fun m -> m "Receive a unwanted command") )
| `STAT ->
stat oc <&> Logs_lwt.debug (fun m -> m "Receive a stat command")
| _ ->
Logs_lwt.warn (fun m -> m "Receive a unwanted command") )
| Result.Error e ->
Logs_lwt.err (fun m ->
m "Error during the reception of the computation: %s"
......
......@@ -15,8 +15,10 @@ let lwt_reporter () =
let k () =
let write () =
match level with
| Logs.App -> Lwt_io.write Lwt_io.stdout (app_flush ())
| _ -> Lwt_io.write Lwt_io.stderr (dst_flush ())
| Logs.App ->
Lwt_io.write Lwt_io.stdout (app_flush ())
| _ ->
Lwt_io.write Lwt_io.stderr (dst_flush ())
in
let unblock () = over () ; Lwt.return_unit in
Lwt.async (fun () -> Lwt.finalize write unblock) ;
......@@ -33,7 +35,7 @@ let setup_log style_renderer level =
()
let setup_log =
Term.(const setup_log $ Fmt_cli.style_renderer () $ Logs_cli.level ())
Term.(const setup_log $ Fmt_cli.style_renderer () $ Logs_cli.level ())
let node_cmd =
let config =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment