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
andon_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 hostConvenience 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 cron_opts() :: job_opts().
-type cron_time() :: {integer(), am | pm} | {integer(), integer(), am | pm} | calendar:time().
-type dom() :: integer().
-type dow_day() :: mon | tue | wed | thu | fri | sat | sun.
-type duration() :: {integer(), hr | h | min | m | sec | s}.
-type job_end() :: fun((JobRef :: job_ref(), Res :: {ok, term()} | {error, {Reason :: term(), Stack :: list()}}) -> term()).
-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()}.
- hostnames => [Hostname]
- List of hostnames where the job is allowed to run
- id => ID
- An identifier of the job passed to
on_job_start
andon_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().
-type job_start() :: fun((JobRef :: job_ref()) -> ignore | any()).
ignore
atom, the job function will not be executed.
-type milliseconds() :: integer().
-type period() :: cron_time() | {every, duration()} | {every, duration(), constraint()}.
-type seconds() :: integer().
Link to this section Functions
-spec cancel(job_ref()) -> boolean().
-spec cron(job_ref(), job(), job_opts()) -> job_ref() | ignored | already_started | {error, term()}.
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 datetime() -> {calendar:datetime(), milliseconds()}.
-spec epoch() -> milliseconds().
-spec epoch_seconds() -> seconds().
-spec get_all_jobs() -> [job_ref()].
-spec multi_set_datetime(calendar:datetime()) -> {Replies, BadNodes} when Replies :: [{node(), ok | {error, term()}}], BadNodes :: [node()].
-spec multi_set_datetime([node()], calendar:datetime()) -> {Replies, BadNodes} when Replies :: [{node(), ok | {error, term()}}], BadNodes :: [node()].
-spec ref_datetime() -> {calendar:datetime(), milliseconds()}.
-spec reset_datetime() -> ok.
-spec set_datetime(calendar:datetime()) -> ok.
-spec set_datetime(calendar:datetime(), local | universal) -> ok.
TZ` parameter must contain an atom `local|universal
.
-spec validate(run_when()) -> ok | {error, term()}.