ecrn_agent (erlcron v1.3.8)
Per-job gen_server that manages the lifecycle of a single scheduled job.
When a job is added to the scheduler, one ecrn_agent process is started
for it. The process calculates the duration until the job's next execution
time and uses gen_server timeouts to sleep for exactly that long. To
avoid accumulated drift from DST transitions or other system-clock changes,
the sleep duration is capped at 30 minutes; the next execution time is then
recalculated from scratch at each wake-up.
The module also exposes the schedule normalisation and next-run calculation
logic through the public functions normalize/2, and until_next_time/2,
which are used by the test suite.
Summary
Functions
Return the time (millisecond epoch) at which the job is next scheduled to run
Run the job immediately, without affecting the next scheduled run time
Start a job agent linked to the calling process
Calculate the duration in milliseconds until Sched next fires, relative to NowEpochTime.
Validate a erlcron:schedule/0 spec without scheduling it.
Types
-type normalized_sched() :: {once, {relative | absolute, integer()}} | {daily, normalized_period()} | {weekly, [integer()], normalized_period()} | {monthly, integer(), normalized_period()}.
Functions
-spec cancel(pid()) -> ok.
-spec get_datetime(pid()) -> calendar:datetime().
-spec get_datetime(pid(), local | universal) -> calendar:datetime().
-spec next_run(pid()) -> erlang:timestamp().
Return the time (millisecond epoch) at which the job is next scheduled to run
-spec normalize(erlcron:schedule(), calendar:datetime()) -> normalized_sched().
-spec recalculate(pid()) -> ok.
-spec run(pid()) -> ok.
Run the job immediately, without affecting the next scheduled run time
-spec set_datetime(pid(), calendar:datetime(), erlcron:milliseconds()) -> ok.
-spec set_datetime(pid(), calendar:datetime(), erlcron:milliseconds(), UTC :: local | universal) -> ok | {error, term()}.
-spec start_link(erlcron:job_ref(), erlcron:job(), erlcron:job_opts()) -> ignore | {error, Reason :: term()} | {ok, pid()}.
-spec start_link(erlcron:job_ref(), erlcron:job(), undefined | fun(() -> any()) | fun((erlcron:job_ref(), calendar:datetime()) -> any()), erlcron:job_opts()) -> ignore | {error, Reason :: term()} | {ok, pid()}.
Start a job agent linked to the calling process
-spec until_next_time(erlcron:milliseconds(), erlcron:schedule()) -> erlcron:milliseconds().
Calculate the duration in milliseconds until Sched next fires, relative to NowEpochTime.
This is the stateless public entry point used by the test suite.
-spec validate(erlcron:schedule() | binary() | string()) -> ok | {error, term()}.
Validate a erlcron:schedule/0 spec without scheduling it.
Returns ok when the spec is syntactically and semantically valid,
or {error, Reason} otherwise.