PeaceFounder.Schedulers
PeaceFounder.Schedulers.Scheduler
— Typemutable struct Scheduler
condition::Condition
pool_interval::Union{Int, Nothing}
retry_interval::Union{Int, Nothing}
delay::Int
started::Bool
finished::Bool
schedule::Vector{Tuple{DateTime, <:Any}}
end
Represents a waitable object which resumes at predetermined scheduled times. A typical use for it is in the event loop like:
scheduler = Scheduler(; retry_interval = 1)
lock(scheduler) do
schedule!(scheduler, now() + Second(1), value)
end
while true
value = wait(scheduler)
try
# Do some stuff
catch
retry!(scheduler)
end
end
In the event loop one manages a state machine which can succed and fail. If it succeds a scheduled time is taken out from the scheduler and proceeds waiting the next event. In the case event at scheduled time had failed the scheduler is notified with retry!
method and attempts to run the event loop againafter retry_interval
until succeeds.
Base.lock
— Methodlock(scheduler::Scheduler)
Lock a scheduler. This is necessary to avoid simultanous modifications of the schedule
field. Note that other Scheduler
fields are not protected with the lock as thoose are considered internal.
Base.notify
— Methodnotify(scheduler::Scheduler[, value])
Notify a scheduler with a value which is returned at wait
.
Base.wait
— Methodwait(scheduler::Scheduler)
Wait until next event is reached and return it's value. In the case event have run through smoothelly the scheduler event is droped with the next wait
call. See also retry!
method.
PeaceFounder.Schedulers.next_event
— Methodnext_event(scheduler::Scheduler)
Return the next event in seconds and coresponding event value. Return nothing if no events are scheduled.
PeaceFounder.Schedulers.retry!
— Methodretry!(scheduler::Scheduler)
Notifies the scheduler that event have run unsucesfully which reschedules it after specified retry_time
(See Scheduler
).
PeaceFounder.Schedulers.schedule!
— Methodschedule!(scheduler::Scheduler, timestamp::DateTime[, value])
Schedule an event at timestamp
with a provided value
. To avoid messing up a schedule acquire a scheduler's lock before adding the event as:
lock(scheduler) do
schedule!(scheduler, now() + Second(1), value)
end
PeaceFounder.Schedulers.waituntil
— Methodwaituntil(time::DateTime)
Waits until given time
is reached.