View Source Crontab.Scheduler (crontab v1.1.14)
This module provides the functionality to retrieve the next run date or the
previous run date from a %CronExpression{}
.
Summary
Functions
This function provides the functionality to retrieve the next run date from a
%Crontab.CronExpression{}
.
This function provides the functionality to retrieve the next run date from a
%Crontab.CronExpression{}
.
Find the next execution dates relative to a given date from a %CronExpression{}
.
This function provides the functionality to retrieve the previous run date
from a %Crontab.CronExpression{}
.
This function provides the functionality to retrieve the previous run date
from a %Crontab.CronExpression{}
.
Find the previous n execution dates relative to a given date from a %CronExpression{}
.
Types
@type direction() :: :increment | :decrement
@type result() :: maybe(NaiveDateTime.t(), any())
Functions
get_next_run_date(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()), max_runs \\ 10000)
View Source@spec get_next_run_date(Crontab.CronExpression.t(), NaiveDateTime.t(), integer()) :: result()
This function provides the functionality to retrieve the next run date from a
%Crontab.CronExpression{}
.
Examples
iex> Crontab.Scheduler.get_next_run_date(%Crontab.CronExpression{}, ~N[2002-01-13 23:00:07])
{:ok, ~N[2002-01-13 23:01:00]}
iex> Crontab.Scheduler.get_next_run_date(%Crontab.CronExpression{year: [{:/, :*, 9}]}, ~N[2002-01-13 23:00:07])
{:ok, ~N[2007-01-01 00:00:00]}
iex> Crontab.Scheduler.get_next_run_date %Crontab.CronExpression{reboot: true}
** (RuntimeError) Special identifier @reboot is not supported.
get_next_run_date!(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()), max_runs \\ 10000)
View Source@spec get_next_run_date!(Crontab.CronExpression.t(), NaiveDateTime.t(), integer()) :: NaiveDateTime.t() | no_return()
This function provides the functionality to retrieve the next run date from a
%Crontab.CronExpression{}
.
Examples
iex> Crontab.Scheduler.get_next_run_date!(%Crontab.CronExpression{}, ~N[2002-01-13 23:00:07])
~N[2002-01-13 23:01:00]
iex> Crontab.Scheduler.get_next_run_date!(%Crontab.CronExpression{year: [1990]}, ~N[2002-01-13 23:00:07])
** (RuntimeError) No compliant date was found for your interval.
iex> Crontab.Scheduler.get_next_run_date!(%Crontab.CronExpression{year: [{:/, :*, 9}]}, ~N[2002-01-13 23:00:07])
~N[2007-01-01 00:00:00]
iex> Crontab.Scheduler.get_next_run_date! %Crontab.CronExpression{reboot: true}
** (RuntimeError) Special identifier @reboot is not supported.
get_next_run_dates(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()))
View Source@spec get_next_run_dates(Crontab.CronExpression.t(), NaiveDateTime.t()) :: Enumerable.t()
Find the next execution dates relative to a given date from a %CronExpression{}
.
Examples
iex> Enum.take(Crontab.Scheduler.get_next_run_dates(
...> %Crontab.CronExpression{extended: true}, ~N[2016-12-17 00:00:00]), 3)
[
~N[2016-12-17 00:00:00],
~N[2016-12-17 00:00:01],
~N[2016-12-17 00:00:02]
]
iex> Enum.take(Crontab.Scheduler.get_next_run_dates(%Crontab.CronExpression{}, ~N[2016-12-17 00:00:00]), 3)
[
~N[2016-12-17 00:00:00],
~N[2016-12-17 00:01:00],
~N[2016-12-17 00:02:00]
]
iex> Enum.take(Crontab.Scheduler.get_next_run_dates(%Crontab.CronExpression{
...> year: [2017], month: [1], day: [1], hour: [0], minute: [1]}, ~N[2016-12-17 00:00:00]), 3)
[~N[2017-01-01 00:01:00]]
iex> Enum.take(Crontab.Scheduler.get_next_run_dates(%Crontab.CronExpression{reboot: true}), 3)
** (RuntimeError) Special identifier @reboot is not supported.
get_previous_run_date(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()), max_runs \\ 10000)
View Source@spec get_previous_run_date(Crontab.CronExpression.t(), NaiveDateTime.t(), integer()) :: result()
This function provides the functionality to retrieve the previous run date
from a %Crontab.CronExpression{}
.
Examples
iex> Crontab.Scheduler.get_previous_run_date %Crontab.CronExpression{}, ~N[2002-01-13 23:00:07]
{:ok, ~N[2002-01-13 23:00:00]}
iex> Crontab.Scheduler.get_previous_run_date %Crontab.CronExpression{
...> year: [{:/, :*, 9}]}, ~N[2002-01-13 23:00:07]
{:ok, ~N[1998-12-31 23:59:00]}
iex> Crontab.Scheduler.get_previous_run_date %Crontab.CronExpression{reboot: true}
** (RuntimeError) Special identifier @reboot is not supported.
get_previous_run_date!(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()), max_runs \\ 10000)
View Source@spec get_previous_run_date!(Crontab.CronExpression.t(), NaiveDateTime.t(), integer()) :: NaiveDateTime.t() | no_return()
This function provides the functionality to retrieve the previous run date
from a %Crontab.CronExpression{}
.
Examples
iex> Crontab.Scheduler.get_previous_run_date! %Crontab.CronExpression{}, ~N[2002-01-13 23:00:07]
~N[2002-01-13 23:00:00]
iex> Crontab.Scheduler.get_previous_run_date!(%Crontab.CronExpression{year: [2100]}, ~N[2002-01-13 23:00:07])
** (RuntimeError) No compliant date was found for your interval.
iex> Crontab.Scheduler.get_previous_run_date! %Crontab.CronExpression{
...> year: [{:/, :*, 9}]}, ~N[2002-01-13 23:00:07]
~N[1998-12-31 23:59:00]
iex> Crontab.Scheduler.get_previous_run_date! %Crontab.CronExpression{reboot: true}
** (RuntimeError) Special identifier @reboot is not supported.
get_previous_run_dates(cron_expression, date \\ DateTime.to_naive(DateTime.utc_now()))
View Source@spec get_previous_run_dates(Crontab.CronExpression.t(), NaiveDateTime.t()) :: Enumerable.t()
Find the previous n execution dates relative to a given date from a %CronExpression{}
.
Examples
iex> Enum.take(Crontab.Scheduler.get_previous_run_dates(
...> %Crontab.CronExpression{extended: true}, ~N[2016-12-17 00:00:00]), 3)
[
~N[2016-12-17 00:00:00],
~N[2016-12-16 23:59:59],
~N[2016-12-16 23:59:58]
]
iex> Enum.take(Crontab.Scheduler.get_previous_run_dates(%Crontab.CronExpression{}, ~N[2016-12-17 00:00:00]), 3)
[
~N[2016-12-17 00:00:00],
~N[2016-12-16 23:59:00],
~N[2016-12-16 23:58:00]
]
iex> Enum.take(Crontab.Scheduler.get_previous_run_dates(%Crontab.CronExpression{
...> year: [2017], month: [1], day: [1], hour: [0], minute: [1]}, ~N[2016-12-17 00:00:00]), 3)
[]
iex> Enum.take(Crontab.Scheduler.get_previous_run_dates(%Crontab.CronExpression{reboot: true}), 3)
** (RuntimeError) Special identifier @reboot is not supported.