This commit is contained in:
bparodi@lezzo.org 2024-11-06 18:56:13 +01:00
parent 47c378bfec
commit c0cec8f1c1
2 changed files with 8 additions and 10 deletions

View file

@ -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

View file

@ -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?)
()
}