crontab() = #{second => '*' | [0..59 | {0..58, 1..59}, ...], minute => '*' | [0..59 | {0..58, 1..59}, ...], hour => '*' | [0..23, ...], month => '*' | [1..12 | {1..11, 2..12}, ...], day_of_month => '*' | [1..31 | {1..30, 2..31}, ...], day_of_week => '*' | [0..6 | {0..5, 1..6}, ...]}
crontab_spec() = crontab() | string() | binary() | 1..4294967
ecron() = #{name => name(), crontab => crontab(), start_time => calendar:rfc3339_string() | unlimited, end_time => calendar:rfc3339_string() | unlimited, mfa => mfa(), type => cron | every}
end_datetime() = unlimited | calendar:datetime()
name() = term()
option() = {singleton, boolean()} | {max_count, pos_integer() | unlimited}
options() = [option()]
parse_error() = invalid_time | invalid_spec | month | day_of_month | day_of_week | hour | minute | second
start_datetime() = unlimited | calendar:datetime()
statistic() = #{ecron => ecron(), status => status(), failed => non_neg_integer(), ok => non_neg_integer(), results => [term()], run_microsecond => [pos_integer()], time_zone => local | utc, worker => pid(), next => [calendar:datetime()]}
status() = waiting | running | deactivate | activate | already_ended
activate(JobName::name()) -> ok | {error, not_found}
activate an exist job, if the job is nonexistent, return {error, not_found}
.
if the job is already activate, nothing happened.
the same effect as reinstall the job from now on.
add(JobName::name(), Spec::crontab_spec(), MFA::mfa()) -> {ok, name()} | {error, parse_error(), term()} | {error, already_exist}
Equivalent to add(JobName, Spec, MFA, unlimited, unlimited, []).
add(JobName::name(), Spec::crontab_spec(), MFA::mfa(), Start::start_datetime(), End::end_datetime(), Option::options()) -> {ok, name()} | {error, parse_error(), term()} | {error, already_exist}
Add new crontab job. All jobs that exceed the limit will be automatically removed.
JobName
: The unique name of job, return {error, already_exist}
if JobName is already exist.Spec
: A cron expression represents a set of times.MFA
: Spawn a process to run MFA when crontab is triggered.Start
: The job's next trigger time is Calculated from StartDatetime. Keeping unlimited
if start from now on.End
: The job will be remove at end time. Keeping unlimited
if never end.Opts
: The optional list of options. {singleton, true}
: Default job is singleton, Each task cannot be executed concurrently.
{max_count, pos_integer()}
: This task can be run up to MaxCount
times, default is unlimited
.
add_with_count(Spec::crontab_spec(), MFA::mfa(), RunCount::pos_integer()) -> {ok, name()} | {error, parse_error(), term()}
Equivalent to add_with_count(make_ref(), Spec, MFA, RunCount).
add_with_count(JobName::name(), Spec::crontab_spec(), MFA::mfa(), RunCount::pos_integer()) -> {ok, name()} | {error, parse_error(), term()}
Equivalent to add(make_ref(), Spec, MFA, unlimited, unlimited, [{max_count, RunCount}]).
add_with_datetime(Spec::crontab_spec(), MFA::mfa(), Start::start_datetime(), End::end_datetime()) -> {ok, name()} | {error, parse_error(), term()}
Equivalent to add(make_ref(), Spec, MFA, Start, End, []).
add_with_datetime(JobName::name(), Spec::crontab_spec(), MFA::mfa(), Start::start_datetime(), End::end_datetime()) -> {ok, name()} | {error, parse_error(), term()} | {error, already_exist}
Equivalent to add(JobName, Spec, MFA, Start, End, []).
deactivate(JobName::name()) -> ok | {error, not_found}
deactivate an exist job, if the job is nonexistent, return {error, not_found}
.
just freeze the job, use @see activate/1 to unfreeze job.
delete(JobName::name()) -> ok
Delete an exist job, if the job is nonexistent, nothing happened.
parse_spec(Error::crontab_spec(), Num::pos_integer()) -> {ok, #{type => cron | every, crontab => crontab_spec(), next => [calendar:rfc3339_string()]}} | {error, atom(), term()}
parse a crontab spec with next trigger time. For debug.
send_after(Spec::crontab_spec(), Pid::pid() | atom(), Message::term()) -> {ok, reference()} | {error, parse_error(), term()}
Starts a timer which will send the message Msg to Dest when crontab is triggered.
erlang:send_after/3
expect the Time
format. erlang:cancel_timer(Ref)
not ecron:delete/1
.send_interval(Spec::crontab_spec(), Pid::pid(), Message::term()) -> {ok, name()} | {error, parse_error(), term()}
Equivalent to send_interval(make_ref(), Spec, Pid, Message, unlimited, unlimited, []).
send_interval(Spec::crontab_spec(), Message::term(), Start::start_datetime(), End::end_datetime(), Option::options()) -> {ok, name()} | {error, parse_error(), term()} | {error, already_exist}
Equivalent to send_interval(make_ref(), Spec, self(), Message, Start, End, Option).
send_interval(JobName::name(), Spec::crontab_spec(), Pid::pid(), Message::term(), Start::start_datetime(), End::end_datetime(), Option::options()) -> {ok, name()} | {error, parse_error(), term()} | {error, already_exist}
Evaluates Pid ! Message repeatedly when crontab is triggered. (Pid can also be an atom of a registered name.)
JobName
: The unique name of job, return {error, already_exist}
if the name is already exist.Spec
: A cron expression represents a set of times.Pid
: The target pid which receive message.Message
: Any erlang term.Start
: The job's next trigger time is Calculated from StartDatetime. Keeping unlimited
if start from now on.End
: The job will be remove at end time. Keeping unlimited
if never end.Opts
: The optional list of options. {singleton, true}
: Default job is singleton, Each task cannot be executed concurrently.
{max_count, pos_integer()}
: This task can be run up to MaxCount
times, default is unlimited
.
statistic() -> [statistic()]
Statistic for all jobs.
statistic(JobName::name()) -> {ok, statistic()} | {error, not_found}
Statistic from an exist job.
if the job is nonexistent, return {error, not_found}
.
Generated by EDoc