client.ml 997 Bytes
Newer Older
1
open Lwt.Infix
Fardale's avatar
Fardale committed
2 3
open Serialization_t

4
let cmd cpu ram time iteration port script_file pass addr () =
Fardale's avatar
Fardale committed
5 6 7 8
  let script = CCIO.with_in script_file CCIO.read_all in
  let submission = {script; time; iteration; cpu; ram; pass} in
  Lwt_io.with_connection
    (Lwt_unix.ADDR_INET (Unix.inet_addr_of_string addr, port))
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    (fun (ic, oc) ->
      Lwt_io.write_line oc (Serialization_j.string_of_query (`JOB submission))
      >>= fun () ->
      Lwt_io.read ic
      >>= fun json ->
      match
        CCResult.guard (fun () -> Serialization_j.answer_of_string json)
      with
      | Ok answer -> (
        match answer with
        | `Ok ->
            Logs_lwt.info (fun m -> m "Computation successfully sent.")
        | `Error s ->
            Logs_lwt.err (fun m ->
                m "Error during the reception of the computation: %s" s ) )
      | Error e ->
          Logs_lwt.err (fun m ->
              m "Error during the reception of the answer: %s"
                (Printexc.to_string e) ) )