Commits

Anonymous committed f5fc28d

kosherized logging

Comments (0)

Files changed (1)

+(*
+2. сделать так, чтобы процесс при падении куда-то писал в лог.
+3. продумать логи.
+*)
+
+module L = Parvel_log;
+
 module type COUNTER
  =
   sig
       [ Some _ -> failwith "dest_put: already put"
       | None ->
           ( d.dest_ref.val := Some v
+          ; L.debug "dest_put: put"
           ; match d.dest_kind with
             [ DLocal ap ->
                 try ap () with
         match smsg with
         [ Async msg -> process_pass_msg_sync disp msg
         | Sync msg sink ->
+            let () = L.debug "process_loop: sync msg" in
             process_pass_msg_sync disp msg >>= fun res ->
+            let () = L.debug "process_loop: passed to process" in
             ( IO.put_sink sink ()
+            ; L.debug "process_loop: sink put"
             ; IO.return res
             )
         ]
     value dest_get
      : dest 'o -> IO.m (call_resp 'o)
      = fun d ->
+         let () = L.debug "Parvel.dest_get" in
          (
          match d.dest_kind with
          [ DLocal _ap -> IO.return "DLocal"
              | Cmd (`Exited (the_pid, status)) ->
                  (match status with
                   [ PE_Normal ->
-                      IO.printf "Parvel.switch: normal worker's exit.  wtf?\n"
+                      let () = L.error
+                        "Parvel.switch: normal worker's exit.  wtf?" in
+                      IO.return ()
                   | PE_Error _ ->
                       IO.return ()
                   ]
              let __ () =
              ( List.iter
                  (fun (i, _d, _s) ->
-                    dbg "dest found: id = %i\n%!" i
+                    L.debug "dest found: id = %i" i
                  )
                  dests
-             ; printf "dests total: %i\n%!" dests_count
+             ; L.debug "dests total: %i" dests_count
              )
              in
              let proto_call_resp = server & ti_ser ti_proto p in
            (* тут -- только локальный случай. *)
            let () = ignore ti_proto in
            let (source, sink) = IO.pipe1 () in
-           let () = IO.run_and_ignore_result
-             (send_optsync server (Sync (Msg p) sink)) in
-           let () = IO.run_and_ignore_result source in
-           ()
+           let res = IO.runIO
+             ( let () = L.debug "proto_call: before send_optsync" in
+               send_optsync server (Sync (Msg p) sink) >>= fun () ->
+               let () = L.debug "proto_call: send_optsync done" in
+               IO.wait_source source >>= fun () ->
+               let () = L.debug "proto_call: wait_source done" in
+               IO.return ()
+             ) in
+           match res with
+           [ `Ok () -> ()
+           | `Error e -> raise e
+           ]
         ;
 
 
                inner_factory outer_ctx >>= fun inner_disp ->
                let rec outer_disp ~inner_disp = fun
                  [ Msg p as msg ->
+                     let () = L.debug "proto_server: Msg _" in
                      let dests : list
                        (int * (string -> unit) * (unit -> string)
                          * (unit -> bool))
                       =
+                      try
                        (* sort_dests & *)
                        get_dests &
                        ubox ti_proto p
+                      with
+                      [ e -> ( L.error "proto_server: get_dests: %s"
+                         (Printexc.to_string e) ; raise e ) ]
                      in
                      (* пред/пост обработка -- тут. *)
+                     let () = L.debug
+                       "proto_server: passing msg to wrapped proc" in
                      process_pass_msg_sync inner_disp msg >>= fun res ->
+                     let () = L.debug
+                       "proto_server: got result from wrapped proc" in
                        if List.for_all
                             (fun (_, _, _, get_is_filled) -> get_is_filled ())
                             dests
                  ]
                and cont = fun
                  [ Exit pe -> process_exit_by_status pe
-                 | Continue k -> process_continue k
+                 | Continue k -> process_continue & outer_disp ~inner_disp:k
                  ]
                in
                  IO.return & outer_disp ~inner_disp
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.