tarearbol v0.99.10 Tarearbol.Crontab View Source
Helper functions to work with cron
syntax.
Link to this section Summary
Functions
Produces the single formula out of cron record. Might be useful for some external check that requires the single validation call.
Returns the next DateTime
the respective cron
record points to
with a precision given as the third argument (default: :second
.)
Returns the list of all the events after dt
(default: DateTime.utc_now/0
.)
Returns the stream of all the events after dt
(default: DateTime.utc_now/0
.)
Parses the cron string into human-readable representation.
Parses the cron string into Tarearbol.Crontab.t()
struct.
Converts the Time
instance into daily-execution cron string
Link to this section Types
Link to this section Functions
Specs
Produces the single formula out of cron record. Might be useful for some external check that requires the single validation call.
Examples
iex> Tarearbol.Crontab.formula("42 3 28 08 *").formula
"(day == 28) && (rem(day_of_week, 1) == 0) && (hour == 3) && (minute == 42) && (month == 8)"
iex> Tarearbol.Crontab.formula("423 * * * *")
{:error, [minute: {:could_not_parse_field, ["423"]}]}
Specs
next(dt :: nil | DateTime.t(), input :: binary(), opts :: keyword()) :: DateTime.t()
Returns the next DateTime
the respective cron
record points to
with a precision given as the third argument (default: :second
.)
If the first parameter is not given, it assumes the next after now.
Examples
iex> dt = DateTime.from_unix!(1567091960)
~U[2019-08-29 15:19:20Z]
iex> Tarearbol.Crontab.next(dt, "42 3 28 08 *")
[
origin: ~U[2019-08-29 15:19:20Z],
next: ~U[2020-08-28 03:42:00Z],
second: 31494160
]
where origin
contains the timestamp to lookup the next
for, next
is the DateTime
instance of the next event and second
is the
{precision
, difference_in_that_precision
}.
Specs
next_as_list(dt :: nil | DateTime.t(), input :: binary(), opts :: keyword()) :: keyword()
Returns the list of all the events after dt
(default: DateTime.utc_now/0
.)
This function calculates the outcome greedily and, while it might be slightly
faster than Tarearbol.Crontab.next_as_stream/3
, it should not be used for
frequently recurring cron records (like "* * * * *"
.)
Specs
next_as_stream(dt :: nil | DateTime.t(), input :: binary(), opts :: keyword()) :: Enumerable.t()
Returns the stream of all the events after dt
(default: DateTime.utc_now/0
.)
This function calculates the outcome lazily, returning a stream.
See Tarearbol.Crontab.next_as_list/3
for greedy evaluation.
Specs
Parses the cron string into human-readable representation.
This function is exported for debugging purposes only, normally one would call prepare/1
instead.
Input format: "minute hour day/month month day/week".
Examples:
iex> Tarearbol.Crontab.parse "10-30/5 */4 1 */1 6,7"
%Tarearbol.Crontab{
day: "(day == 1)",
day_of_week: "(day_of_week == 6 || day_of_week == 7)",
hour: "(rem(hour, 4) == 0)",
minute: "(rem(minute, 5) == 0 && minute >= 10 && minute <= 30)",
month: "(rem(month, 1) == 0)"
}
In case of malformed input:
iex> Tarearbol.Crontab.parse "10-30/5 */4 1 */1 6d,7"
%Tarearbol.Crontab{
day: "(day == 1)",
day_of_week: {:error, {:could_not_parse_integer, "6d"}},
hour: "(rem(hour, 4) == 0)",
minute: "(rem(minute, 5) == 0 && minute >= 10 && minute <= 30)",
month: "(rem(month, 1) == 0)"
}
Specs
Parses the cron string into Tarearbol.Crontab.t()
struct.
Input format: "minute hour day/month month day/week".
Specs
Converts the Time
instance into daily-execution cron string