more
This commit is contained in:
parent
47c378bfec
commit
c0cec8f1c1
2 changed files with 8 additions and 10 deletions
|
@ -57,8 +57,9 @@ let make (logger: ILogger) =
|
||||||
{connection = conn}
|
{connection = conn}
|
||||||
|
|
||||||
|
|
||||||
let wait_notification (ct: CancellationToken) (db: t) =
|
let wait_notification (ms: int) (ct: CancellationToken) (db: t) =
|
||||||
db.connection.WaitAsync ct
|
db.connection.WaitAsync (ms, ct)
|
||||||
|
|
||||||
|
|
||||||
let gather_requirements (hostname: string) (ct: CancellationToken) (db: t) =
|
let gather_requirements (hostname: string) (ct: CancellationToken) (db: t) =
|
||||||
let query = """select
|
let query = """select
|
||||||
|
|
|
@ -70,6 +70,7 @@ type Bidello(client: IClusterClient) =
|
||||||
|> Result.toOption
|
|> Result.toOption
|
||||||
|> Option.bind (function | [] -> None | xs -> Some xs)
|
|> Option.bind (function | [] -> None | xs -> Some xs)
|
||||||
|> Option.map (fun xs -> List.minBy (_.scheduled_at) xs |> _.scheduled_at)
|
|> Option.map (fun xs -> List.minBy (_.scheduled_at) xs |> _.scheduled_at)
|
||||||
|
|> Option.defaultValue Instant.MaxValue
|
||||||
|
|
||||||
match todo_list with
|
match todo_list with
|
||||||
| Error e -> logger.Error $"Can't schedule cronjobs. Reason: {e}"
|
| Error e -> logger.Error $"Can't schedule cronjobs. Reason: {e}"
|
||||||
|
@ -77,14 +78,10 @@ type Bidello(client: IClusterClient) =
|
||||||
cronjobs
|
cronjobs
|
||||||
|> Seq.iter schedule_jobs
|
|> Seq.iter schedule_jobs
|
||||||
|
|
||||||
let! _wake_up =
|
let timeout = next_job_at - now |> _.TotalMilliseconds |> floor |> int32
|
||||||
match next_job_at with
|
// printfn $"Waking up in: {timeout}|{next_job_at}"
|
||||||
| None -> db |> Database.wait_notification ct
|
let! _wake_up = db |> Database.wait_notification timeout ct
|
||||||
| Some time ->
|
// TODO: se il lavoro da fare, è già in esecuzione (e ancora non terminato, che fare?)
|
||||||
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]
|
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue