Skip to content

Commit

Permalink
CP-51690: [prep] Xapi_periodic_scheduler: Factor out Delay.wait call
Browse files Browse the repository at this point in the history
No functional change.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Nov 18, 2024
1 parent b6952d6 commit 95dbc42
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions ocaml/xapi/xapi_periodic_scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95dbc42

Please sign in to comment.