From 95dbc42a73f94750a92484259f7bbef7b43ee04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 21 Apr 2024 14:29:03 +0100 Subject: [PATCH] CP-51690: [prep] Xapi_periodic_scheduler: Factor out Delay.wait call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No functional change. Signed-off-by: Edwin Török --- ocaml/xapi/xapi_periodic_scheduler.ml | 31 +++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/ocaml/xapi/xapi_periodic_scheduler.ml b/ocaml/xapi/xapi_periodic_scheduler.ml index 1edcb938857..25bb7a49f73 100644 --- a/ocaml/xapi/xapi_periodic_scheduler.ml +++ b/ocaml/xapi/xapi_periodic_scheduler.ml @@ -58,6 +58,22 @@ let remove_from_queue name = if index > -1 then Ipq.remove queue index +let wait_next sleep = + try ignore (Delay.wait delay sleep) + with e -> + let detailed_msg = + match e with + | Unix.Unix_error (code, _, _) -> + Unix.error_message code + | _ -> + "unknown error" + in + error + "Could not schedule interruptable delay (%s). Falling back to normal \ + delay. New events may be missed." + detailed_msg ; + Thread.delay sleep + let loop () = debug "Periodic scheduler started" ; try @@ -85,20 +101,7 @@ let loop () = |> Mtime.Span.add (Clock.span 0.001) |> Scheduler.span_to_s in - try ignore (Delay.wait delay sleep) - with e -> - let detailed_msg = - match e with - | Unix.Unix_error (code, _, _) -> - Unix.error_message code - | _ -> - "unknown error" - in - error - "Could not schedule interruptable delay (%s). Falling back to \ - normal delay. New events may be missed." - detailed_msg ; - Thread.delay sleep + wait_next sleep done with _ -> error