From c0cec8f1c1c3f82d972153e5d5e25729e2203853 Mon Sep 17 00:00:00 2001 From: "bparodi@lezzo.org" Date: Wed, 6 Nov 2024 18:56:13 +0100 Subject: [PATCH] more --- src/Database.fs | 5 +++-- src/Library.fs | 13 +++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Database.fs b/src/Database.fs index a39b376..c7c2a4b 100644 --- a/src/Database.fs +++ b/src/Database.fs @@ -57,8 +57,9 @@ let make (logger: ILogger) = {connection = conn} -let wait_notification (ct: CancellationToken) (db: t) = - db.connection.WaitAsync ct +let wait_notification (ms: int) (ct: CancellationToken) (db: t) = + db.connection.WaitAsync (ms, ct) + let gather_requirements (hostname: string) (ct: CancellationToken) (db: t) = let query = """select diff --git a/src/Library.fs b/src/Library.fs index c06a7e4..641aab1 100644 --- a/src/Library.fs +++ b/src/Library.fs @@ -70,6 +70,7 @@ type Bidello(client: IClusterClient) = |> Result.toOption |> Option.bind (function | [] -> None | xs -> Some xs) |> Option.map (fun xs -> List.minBy (_.scheduled_at) xs |> _.scheduled_at) + |> Option.defaultValue Instant.MaxValue match todo_list with | Error e -> logger.Error $"Can't schedule cronjobs. Reason: {e}" @@ -77,14 +78,10 @@ type Bidello(client: IClusterClient) = cronjobs |> Seq.iter schedule_jobs - let! _wake_up = - match next_job_at with - | None -> db |> Database.wait_notification ct - | Some time -> - let by_ = time - now |> _.TotalMilliseconds |> floor |> int32 - let db_change = db |> Database.wait_notification ct - let timer = Task.Delay (by_, ct) - Task.WhenAny [timer; db_change] + let timeout = next_job_at - now |> _.TotalMilliseconds |> floor |> int32 + // printfn $"Waking up in: {timeout}|{next_job_at}" + let! _wake_up = db |> Database.wait_notification timeout ct + // TODO: se il lavoro da fare, è già in esecuzione (e ancora non terminato, che fare?) () }