Contents
- Duration
- Milliseconds
- Duration (double milliseconds)
- Zero = new(0)
- random (Duration min, Duration max, Option<int> seed = default)
- == (Duration a, Duration b)
- != (Duration a, Duration b)
- Equals (Duration other)
- Equals (object? obj)
- GetHashCode ()
- CompareTo (Duration other)
- > (Duration a, Duration b)
- >= (Duration a, Duration b)
- < (Duration a, Duration b)
- <= (Duration a, Duration b)
- ToString ()
- Schedule
- Identity = Transform(identity)
- TimeSeries (params Duration[] durations)
- TimeSeries (Arr<Duration> durations)
- TimeSeries (Seq<Duration> durations)
- TimeSeries (Lst<Duration> durations)
- TimeSeries (Set<Duration> durations)
- TimeSeries (HashSet<Duration> durations)
- Transform (Func<Schedule, Schedule> transform)
- Forever = SchForever.Default
- Never = SchNever.Default
- Once = Forever.Take(1)
- NoDelayOnFirst = Transform(s => s.Tail.Prepend(Duration.Zero))
- RepeatForever = Transform(s => new SchRepeatForever(s))
- recurs (int times)
- spaced (Duration space)
- linear (Duration seed, double factor = 1)
- exponential (Duration seed, double factor = 2)
- fibonacci (Duration seed)
- upto (Duration max, Func<DateTime>? currentTimeFn = null)
- fixedInterval (Duration interval, Func<DateTime>? currentTimeFn = null)
- windowed (Duration interval, Func<DateTime>? currentTimeFn = null)
- secondOfMinute (int second, Func<DateTime>? currentTimeFn = null)
- minuteOfHour (int minute, Func<DateTime>? currentTimeFn = null)
- hourOfDay (int hour, Func<DateTime>? currentTimeFn = null)
- dayOfWeek (DayOfWeek day, Func<DateTime>? currentTimeFn = null)
- maxDelay (Duration max)
- maxCumulativeDelay (Duration max)
- jitter (Duration minRandom, Duration maxRandom, Option<int> seed = default)
- jitter (double factor = 0.5, Option<int> seed = default)
- decorrelate (double factor = 0.1, Option<int> seed = default)
- resetAfter (Duration max)
- repeat (int times)
- intersperse (Schedule schedule)
- intersperse (params Duration[] durations)
- Spaced (Duration space)
- Recurs (int times)
- Exponential (Duration seed, double factor = 2)
- Fibonacci (Duration seed)
- Schedule
- | (Schedule a, Schedule b)
- | (Schedule a, ScheduleTransformer b)
- | (ScheduleTransformer a, Schedule b)
- & (Schedule a, Schedule b)
- & (Schedule a, ScheduleTransformer b)
- & (ScheduleTransformer a, Schedule b)
- + (Schedule a, Schedule b)
- Run ()
- Intersect (Schedule b)
- Union (Schedule b)
- Interleave (Schedule b)
- Combine (Schedule b)
- Take (int amount)
- Skip (int amount)
- Tail
- Prepend (Duration value)
- PrependZero
- Map (Func<Duration, Duration> f)
- Map (Func<Duration, int, Duration> f)
- Filter (Func<Duration, bool> pred)
- Where (Func<Duration, bool> pred)
- Select (Func<Duration, Duration> f)
- Select (Func<Duration, int, Duration> f)
- Bind (Func<Duration, Schedule> f)
- SelectMany (Func<Duration, Schedule> f)
- SelectMany (Func<Duration, Schedule> bind, Func<Duration, Duration, Duration> project)
- ScheduleExtensions
- ToSchedule (this Seq<Duration> seq)
- ToSchedule (this Arr<Duration> array)
- ToSchedule (this Lst<Duration> list)
- ToSchedule (this Set<Duration> set)
- ToSchedule (this HashSet<Duration> hashSet)
- Cons (this Duration value, Schedule s)
- Prelude
- intersect (Schedule a, Schedule b)
- union (Schedule a, Schedule b)
- interleave (Schedule a, Schedule b)
- append (Schedule a, Schedule b)
- take (Schedule s, int amount)
- skip (Schedule s, int amount)
- tail (Schedule s)
- map (Schedule s, Func<Duration, Duration> f)
- filter (Schedule s, Func<Duration, bool> pred)
- bind (Schedule s, Func<Duration, Schedule> f)
- ScheduleTransformer
Period of time in milliseconds. Can be used to convert between other duration like types, such as TimeSpan and Time.
Fields
field double Milliseconds Source #
field Duration Zero = new(0) Source #
Zero magnitude duration (instant)
Constructors
Methods
method Duration random (Duration min, Duration max, Option<int> seed = default) Source #
Random duration between the provided min and max durations.
This can be used to seed a schedule in parallel. Providing another method of de-correlation.
For example, this is a linear schedule that,
starts with a seed duration between 10 and 50 milliseconds
includes a 10% jitter, added and removed in sequence from each duration
recurring 5 times
Schedule.linear(Duration.Random(10ms, 50ms)) | Schedule.decorrelate() | Schedule.recurs(5)
Three runs result in,
(25ms, 23ms, 50ms, 47ms, 72ms)
(13ms, 11ms, 25ms, 23ms, 40ms)
(28ms, 25ms, 56ms, 53ms, 87ms)
Parameters
param | min | min duration |
param | max | max duration |
param | seed | optional seed |
returns | random duration between min and max duration |
method int GetHashCode () Source #
Fields
field ScheduleTransformer Identity = Transform(identity) Source #
Identity or no-op schedule result transformer
field Schedule Forever = SchForever.Default Source #
Schedule that runs forever
field Schedule Never = SchNever.Default Source #
Schedule that never runs
field Schedule Once = Forever.Take(1) Source #
Schedule that runs once
field ScheduleTransformer NoDelayOnFirst = Transform(s => s.Tail.Prepend(Duration.Zero)) Source #
A schedule transformer that will enforce the first retry has no delay
field ScheduleTransformer RepeatForever = Transform(s => new SchRepeatForever(s)) Source #
Repeats the schedule forever
Methods
method Schedule TimeSeries (params Duration[] durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method Schedule TimeSeries (Arr<Duration> durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method Schedule TimeSeries (Seq<Duration> durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method Schedule TimeSeries (Lst<Duration> durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method Schedule TimeSeries (Set<Duration> durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method Schedule TimeSeries (HashSet<Duration> durations) Source #
Schedule
constructor that recurs for the specified durations
Parameters
param | durations | durations to apply |
method ScheduleTransformer Transform (Func<Schedule, Schedule> transform) Source #
ScheduleTransformer
constructor which provides mapping capabilities for Schedule
instances
Parameters
param | transform | Transformation function |
returns |
|
method ScheduleTransformer recurs (int times) Source #
Schedule transformer that limits the schedule to run the specified number of times
Parameters
param | times | number of times |
method Schedule spaced (Duration space) Source #
Schedule that recurs continuously with the given spacing
Parameters
param | space | space |
method Schedule linear (Duration seed, double factor = 1) Source #
Schedule that recurs continuously using a linear backoff
Parameters
param | seed | seed |
param | factor | optional factor to apply, default 1 |
method Schedule exponential (Duration seed, double factor = 2) Source #
Schedule that recurs continuously using a exponential backoff
Parameters
param | seed | seed |
param | factor | optional factor to apply, default 2 |
method Schedule fibonacci (Duration seed) Source #
Schedule that recurs continuously using a fibonacci based backoff
Parameters
param | seed | seed |
method Schedule upto (Duration max, Func<DateTime>? currentTimeFn = null) Source #
Schedule that runs for a given duration
Parameters
param | max | max duration to run the schedule for |
param | currentTimeFn | current time function |
method Schedule fixedInterval (Duration interval, Func<DateTime>? currentTimeFn = null) Source #
Schedule that recurs on a fixed interval.
If the action run between updates takes longer than the interval, then the action will be run immediately, but re-runs will not "pile up".
|-----interval-----|-----interval-----|-----interval-----|
|---------action--------||action|-----|action|-----------|
Parameters
param | interval | schedule interval |
param | currentTimeFn | current time function |
method Schedule windowed (Duration interval, Func<DateTime>? currentTimeFn = null) Source #
A schedule that divides the timeline into interval
-long windows, and sleeps
until the nearest window boundary every time it recurs.
For example, Windowed(10 * seconds)
would produce a schedule as follows:
10s 10s 10s 10s
|----------|----------|----------|----------|
|action------|sleep---|act|-sleep|action----|
Parameters
param | interval | schedule interval |
param | currentTimeFn | current time function |
method Schedule secondOfMinute (int second, Func<DateTime>? currentTimeFn = null) Source #
Cron-like schedule that recurs every specified second
of each minute
Parameters
param | second | second of the minute, will be rounded to fit between 0 and 59 |
param | currentTimeFn | current time function |
method Schedule minuteOfHour (int minute, Func<DateTime>? currentTimeFn = null) Source #
Cron-like schedule that recurs every specified minute
of each hour
Parameters
param | minute | minute of the hour, will be rounded to fit between 0 and 59 |
param | currentTimeFn | current time function |
method Schedule hourOfDay (int hour, Func<DateTime>? currentTimeFn = null) Source #
Cron-like schedule that recurs every specified hour
of each day
Parameters
param | hour | hour of the day, will be rounded to fit between 0 and 23 |
param | currentTimeFn | current time function |
method Schedule dayOfWeek (DayOfWeek day, Func<DateTime>? currentTimeFn = null) Source #
Cron-like schedule that recurs every specified day
of each week
Parameters
param | day | day of the week |
param | currentTimeFn | current time function |
method ScheduleTransformer maxDelay (Duration max) Source #
A schedule transformer that limits the returned delays to max delay
Parameters
param | max | max delay to return |
method ScheduleTransformer maxCumulativeDelay (Duration max) Source #
Limits the schedule to the max cumulative delay
Parameters
param | max | max delay to stop schedule at |
method ScheduleTransformer jitter (Duration minRandom, Duration maxRandom, Option<int> seed = default) Source #
A schedule transformer that adds a random jitter to any returned delay
Parameters
param | minRandom | min random milliseconds |
param | maxRandom | max random milliseconds |
param | seed | optional seed |
method ScheduleTransformer jitter (double factor = 0.5, Option<int> seed = default) Source #
A schedule transformer that adds a random jitter to any returned delay
Parameters
param | factor | jitter factor based on the returned delay |
param | seed | optional seed |
method ScheduleTransformer decorrelate (double factor = 0.1, Option<int> seed = default) Source #
Transforms the schedule by de-correlating each of the durations both up and down in a jittered way
Given a linear schedule starting at 100. (100, 200, 300...) Adding de-correlation to it might produce a result like this, (103.2342, 97.123, 202.3213, 197.321...) The overall schedule runs twice as long but should be less correlated when used in parallel.
Parameters
param | factor | jitter factor based on the returned delay |
param | seed | optional seed |
method ScheduleTransformer resetAfter (Duration max) Source #
Resets the schedule after a provided cumulative max duration
Parameters
param | max | max delay to reset the schedule at |
method ScheduleTransformer repeat (int times) Source #
Repeats the schedule n number of times
NOTE: This repeats the entire schedule! Use Schedule.recurs(n)
for 'number of attempts'.
Parameters
param | times | number of times to repeat the schedule |
method ScheduleTransformer intersperse (Schedule schedule) Source #
Intersperse the provided duration(s) between each duration in the schedule
Parameters
param | duration | schedule to intersperse |
method ScheduleTransformer intersperse (params Duration[] durations) Source #
Intersperse the provided duration(s) between each duration in the schedule
Parameters
param | durations | 1 or more durations to intersperse |
method Schedule Exponential (Duration seed, double factor = 2) Source #
A schedule is defined as a potentially infinite stream of durations, combined with mechanisms for composing them.
Used heavily by repeat
, retry
, and fold
with the effect types. Use the static methods to create parts
of schedulers and then union them using |
or intersect them using &
. Union will take the minimum of the two
schedules to the length of the longest, intersect will take the maximum of the two schedules to the length of the
shortest.
Examples
This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds:
var s = Schedule.recurs(5) | Schedule.exponential(10*ms)
This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds and with a maximum delay of 2000 milliseconds:
var s = Schedule.recurs(5) | Schedule.exponential(10*ms) | Schedule.spaced(2000*ms)
This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds and with a minimum delay of 300 milliseconds:
var s = Schedule.recurs(5) | Schedule.exponential(10*ms) & Schedule.spaced(300*ms)
Properties
property Schedule PrependZero Source #
Prepend a zero duration in-front of the rest of the scheduled durations
Parameters
param | value | Duration to prepend |
returns | Schedule with the duration prepended |
Methods
method Iterable<Duration> Run () Source #
Realise the underlying time-series of durations
Parameters
returns | The underlying time-series of durations |
method Schedule Intersect (Schedule b) Source #
Intersection of two schedules. As long as they are both running it returns the max duration
Parameters
param | b | Schedule |
returns | Max of schedule |
method Schedule Union (Schedule b) Source #
Union of two schedules. As long as any are running it returns the min duration of both or a or b
Parameters
param | b | Schedule |
returns | Min of schedule |
method Schedule Interleave (Schedule b) Source #
Interleave two schedules together
Parameters
param | b | Schedule |
returns | Returns the two schedules interleaved together |
method Schedule Combine (Schedule b) Source #
Append two schedules together
Parameters
param | b | Schedule |
returns | Returns the two schedules appended |
method Schedule Take (int amount) Source #
Take amount
durations from the Schedule
Parameters
param | s | Schedule to take from |
param | amount | Amount ot take |
returns | Schedule with |
method Schedule Skip (int amount) Source #
Skip amount
durations from the Schedule
Parameters
param | s | Schedule to skip durations from |
param | amount | Amount ot skip |
returns | Schedule with |
method Schedule Prepend (Duration value) Source #
Prepend a duration in-front of the rest of the scheduled durations
Parameters
param | value | Duration to prepend |
returns | Schedule with the duration prepended |
method Schedule Map (Func<Duration, Duration> f) Source #
Functor map operation for Schedule
Parameters
param | f | Mapping function |
returns | Mapped schedule |
method Schedule Map (Func<Duration, int, Duration> f) Source #
Functor map operation for Schedule
Parameters
param | f | Mapping function |
returns | Mapped schedule |
method Schedule Filter (Func<Duration, bool> pred) Source #
Filter operation for Schedule
Parameters
param | pred | predicate |
returns | Filtered schedule |
method Schedule Where (Func<Duration, bool> pred) Source #
Filter operation for Schedule
Parameters
param | pred | predicate |
returns | Filtered schedule |
method Schedule Select (Func<Duration, Duration> f) Source #
Functor map operation for Schedule
Parameters
param | f | Mapping function |
returns | Mapped schedule |
method Schedule Select (Func<Duration, int, Duration> f) Source #
Functor map operation for Schedule
Parameters
param | f | Mapping function |
returns | Mapped schedule |
method Schedule Bind (Func<Duration, Schedule> f) Source #
Monad bind operation for Schedule
Parameters
param | f | Bind function |
returns | Chained schedule |
method Schedule SelectMany (Func<Duration, Schedule> f) Source #
Monad bind operation for Schedule
Parameters
param | f | Bind function |
returns | Chained schedule |
method Schedule SelectMany (Func<Duration, Schedule> bind, Func<Duration, Duration, Duration> project) Source #
Monad bind and project operation for Schedule
Parameters
param | s | Schedule |
param | bind | Bind function |
param | project | Project function |
returns | Chained schedule |
Operators
class ScheduleExtensions Source #
Methods
method Schedule ToSchedule (this Seq<Duration> seq) Source #
Converts a Seq
of positive durations to a schedule
Parameters
param | seq | Seq of positive durations |
returns | schedule |
method Schedule ToSchedule (this Arr<Duration> array) Source #
Converts a Arr
of positive durations to a schedule
Parameters
param | array | array of positive durations |
returns | schedule |
method Schedule ToSchedule (this Lst<Duration> list) Source #
Converts a Lst
of positive durations to a schedule
Parameters
param | list | list of positive durations |
returns | schedule |
method Schedule ToSchedule (this Set<Duration> set) Source #
Converts a Set
of positive durations to a schedule
Parameters
param | set | set of positive durations |
returns | schedule |
method Schedule ToSchedule (this HashSet<Duration> hashSet) Source #
Converts a HashSet
of positive durations to a schedule
Parameters
param | hashSet | hashset of positive durations |
returns | schedule |
Methods
method Schedule intersect (Schedule a, Schedule b) Source #
Intersection of two schedules. As long as they are both running it returns the max duration
Parameters
param | a | Schedule |
param | b | Schedule |
returns | Max of schedule |
method Schedule union (Schedule a, Schedule b) Source #
Union of two schedules. As long as any are running it returns the min duration of both or a or b
Parameters
param | a | Schedule |
param | b | Schedule |
returns | Min of schedule |
method Schedule interleave (Schedule a, Schedule b) Source #
Interleave two schedules together
Parameters
param | a | Schedule |
param | b | Schedule |
returns | Returns the two schedules interleaved together |
method Schedule append (Schedule a, Schedule b) Source #
Append two schedules together
Parameters
param | a | Schedule |
param | b | Schedule |
returns | Returns the two schedules appended |
method Schedule take (Schedule s, int amount) Source #
Take amount
durations from the Schedule
Parameters
param | s | Schedule to take from |
param | amount | Amount ot take |
returns | Schedule with |
method Schedule skip (Schedule s, int amount) Source #
Skip amount
durations from the Schedule
Parameters
param | s | Schedule to skip durations from |
param | amount | Amount ot skip |
returns | Schedule with |
method Schedule map (Schedule s, Func<Duration, Duration> f) Source #
Functor map operation for Schedule
Parameters
param | s | Schedule |
param | f | Mapping function |
returns | Mapped schedule |