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