View Source erlcron (erlcron v1.2.1)

Link to this section Summary

Types

Cron default options applicable to all jobs. See job_opts().
A function to be called after a job ended. The function is passed the job's result.
Job options:
hostnames => [Hostname]
List of hostnames where the job is allowed to run
id => ID
An identifier of the job passed to on_job_start and on_job_end callbacks. It can be any term.
on_job_start => {Mod, Fun} | fun(JobRef, ID) -> any()
Mod:Fun(Ref::job_ref(), ID::any()) function to call on job start. The result is ignored.
{on_job_start, {Mod, Fun}} | fun(JobRef, ID, Result) -> term()
Mod:Fun(Ref::job_ref(), ID::any(), Result) function to call after a job has ended. Result is {ok, JobResult::term()} or {error, `{Reason, StackTrace}} if there is an exception.
A job reference.
A function to be called before a job is started. If it returns the ignore atom, the job function will not be executed.

Functions

Convenience method to specify a job to run once at the given time or after the amount of time specified.
Cancel the job specified by the jobref.
Adds a new job to the cron system. Jobs are described in the job() spec. It returns the JobRef that can be used to manipulate the job after it is created.
Schedule a job identified by a JobRef. A job reference can be a reference, atom, or binary. If it is an atom, a job will be locally registered by that name. Returns false if the job is not permitted to run on the current host
Convenience method to specify a job run to run on a daily basis at a specific time.
Get the current date time of the erlcron system adjusted to reference.
Get the current date time in seconds millisince epoch.
Get the current date time in seconds since epoch.
Convenience method to specify a job run to run on a weekly basis at a specific time.
Set the current date time of the erlcron system running on different nodes.
Set the current date time of the erlcron system running on the specified nodes
Get the reference date time of the erlcron system.
Reset the reference datetime of erlcron system to current epoch time.
Set the current date time of the running erlcron system using local time.
Set the current date time of the running erlcron system using either local or universal time. The TZ` parameter must contain an atom `local|universal.
Check that the spec specified is valid or invalid
Convenience method to specify a job run to run on a weekly basis at a specific time.

Link to this section Types

-type callable() ::
    {M :: module(), F :: atom(), A :: [term()]} |
    fun(() -> term()) |
    fun((JobRef :: job_ref(), calendar:datetime()) -> term()).
-type constraint() :: {between, cron_time(), cron_time()}.
-type cron_opts() :: job_opts().
Cron default options applicable to all jobs. See job_opts().
-type cron_time() :: {integer(), am | pm} | {integer(), integer(), am | pm} | calendar:time().
-type dom() :: integer().
-type dow() :: dow_day() | [dow_day()].
-type dow_day() :: mon | tue | wed | thu | fri | sat | sun.
-type duration() :: {integer(), hr | h | min | m | sec | s}.
-type job() ::
    {run_when(), callable()} |
    {run_when(), callable(), job_opts()} |
    #{id => job_ref(), interval => run_when(), execute => callable(), _ => any()}.
-type job_end() ::
    fun((JobRef :: job_ref(), Res :: {ok, term()} | {error, {Reason :: term(), Stack :: list()}}) ->
            term()).
A function to be called after a job ended. The function is passed the job's result.
-type job_opts() ::
    #{hostnames => [binary() | string()],
      id => term(),
      on_job_start => {Mod :: atom(), Fun :: atom()} | job_start(),
      on_job_end => {Mod :: atom(), Fun :: atom()} | job_end()}.
Job options:
hostnames => [Hostname]
List of hostnames where the job is allowed to run
id => ID
An identifier of the job passed to on_job_start and on_job_end callbacks. It can be any term.
on_job_start => {Mod, Fun} | fun(JobRef, ID) -> any()
Mod:Fun(Ref::job_ref(), ID::any()) function to call on job start. The result is ignored.
{on_job_start, {Mod, Fun}} | fun(JobRef, ID, Result) -> term()
Mod:Fun(Ref::job_ref(), ID::any(), Result) function to call after a job has ended. Result is {ok, JobResult::term()} or {error, `{Reason, StackTrace}} if there is an exception.
-type job_ref() :: reference() | atom() | binary().
A job reference.
-type job_start() :: fun((JobRef :: job_ref()) -> ignore | any()).
A function to be called before a job is started. If it returns the ignore atom, the job function will not be executed.
-type milliseconds() :: integer().
-type period() :: cron_time() | {every, duration()} | {every, duration(), constraint()}.
-type run_when() ::
    {once, cron_time()} |
    {once, seconds()} |
    {daily, period()} |
    {weekly, dow(), period()} |
    {monthly, dom() | [dom()], period()}.
-type seconds() :: integer().

Link to this section Functions

-spec at(cron_time() | seconds(), callable()) -> job_ref() | ignored | already_started | {error, term()}.
Convenience method to specify a job to run once at the given time or after the amount of time specified.
-spec at(job_ref(), cron_time() | seconds(), function()) ->
      job_ref() | ignored | already_started | {error, term()}.
Link to this function

at(JobRef, When, Fun, Opts)

View Source
-spec at(job_ref(), cron_time() | seconds(), function(), job_opts()) ->
      job_ref() | ignored | already_started | {error, term()}.
-spec cancel(job_ref()) -> boolean().
Cancel the job specified by the jobref.
-spec cron(job()) -> job_ref() | ignored | already_started | {error, term()}.
Adds a new job to the cron system. Jobs are described in the job() spec. It returns the JobRef that can be used to manipulate the job after it is created.
-spec cron(job() | job_ref(), job() | cron_opts()) ->
        job_ref() | ignored | already_started | {error, term()}.
-spec cron(job_ref(), job(), job_opts()) -> job_ref() | ignored | already_started | {error, term()}.
Schedule a job identified by a JobRef. A job reference can be a reference, atom, or binary. If it is an atom, a job will be locally registered by that name. Returns false if the job is not permitted to run on the current host
-spec daily(cron_time() | seconds(), function()) ->
         job_ref() | ignored | already_started | {error, term()}.
Convenience method to specify a job run to run on a daily basis at a specific time.
Link to this function

daily(JobRef, When, Fun)

View Source
-spec daily(job_ref(), cron_time() | seconds(), function()) ->
         job_ref() | ignored | already_started | {error, term()}.
Link to this function

daily(JobRef, When, Fun, Opts)

View Source
-spec daily(job_ref(), cron_time() | seconds(), function(), job_opts()) ->
         job_ref() | ignored | already_started | {error, term()}.
-spec datetime() -> {calendar:datetime(), milliseconds()}.
Get the current date time of the erlcron system adjusted to reference.
-spec epoch() -> milliseconds().
Get the current date time in seconds millisince epoch.
-spec epoch_seconds() -> seconds().
Get the current date time in seconds since epoch.
-spec get_all_jobs() -> [job_ref()].
-spec monthly(dom(), cron_time() | seconds(), function()) ->
           job_ref() | ignored | already_started | {error, term()}.
Convenience method to specify a job run to run on a weekly basis at a specific time.
Link to this function

monthly(JobRef, DOM, When, Fun)

View Source
-spec monthly(job_ref(), dom(), cron_time() | seconds(), function()) ->
           job_ref() | ignored | already_started | {error, term()}.
Link to this function

monthly(JobRef, DOM, When, Fun, Opts)

View Source
-spec monthly(job_ref(), dom(), cron_time() | seconds(), function(), job_opts()) ->
           job_ref() | ignored | already_started | {error, term()}.
Link to this function

multi_set_datetime(DateTime)

View Source
-spec multi_set_datetime(calendar:datetime()) -> {Replies, BadNodes}
                      when Replies :: [{node(), ok | {error, term()}}], BadNodes :: [node()].
Set the current date time of the erlcron system running on different nodes.
Link to this function

multi_set_datetime(Nodes, DateTime)

View Source
-spec multi_set_datetime([node()], calendar:datetime()) -> {Replies, BadNodes}
                      when Replies :: [{node(), ok | {error, term()}}], BadNodes :: [node()].
Set the current date time of the erlcron system running on the specified nodes
-spec ref_datetime() -> {calendar:datetime(), milliseconds()}.
Get the reference date time of the erlcron system.
-spec reset_datetime() -> ok.
Reset the reference datetime of erlcron system to current epoch time.
-spec set_datetime(calendar:datetime()) -> ok.
Set the current date time of the running erlcron system using local time.
Link to this function

set_datetime(DateTime, TZ)

View Source
-spec set_datetime(calendar:datetime(), local | universal) -> ok.
Set the current date time of the running erlcron system using either local or universal time. The TZ` parameter must contain an atom `local|universal.
-spec validate(run_when()) -> ok | {error, term()}.
Check that the spec specified is valid or invalid
-spec weekly(dow(), cron_time() | seconds(), function()) ->
          job_ref() | ignored | already_started | {error, term()}.
Convenience method to specify a job run to run on a weekly basis at a specific time.
Link to this function

weekly(JobRef, DOW, When, Fun)

View Source
-spec weekly(job_ref(), dow(), cron_time() | seconds(), function()) ->
          job_ref() | ignored | already_started | {error, term()}.
Link to this function

weekly(JobRef, DOW, When, Fun, Opts)

View Source
-spec weekly(job_ref(), dow(), cron_time() | seconds(), function(), job_opts()) ->
          job_ref() | ignored | already_started | {error, term()}.