Module crone

Description

Simple task scheduler for Erlang/OTP. This application aims to one day be a viable replacement for cron.

crone is a simple utility which schedules tasks to be run periodically at given times.

crone differs from cron in the following ways:

Function Index

Exported Functions
format_time/1Returns human-readable string from seconds past midnight.
loop_task/1Used by start/1 to wait until the next time each task is scheduled to run, run it, and repeat.
start/1Starts crone, spawning a process for each task.
stop/1Stops all monitoring processes started by crone.
Internal Documented Functions
current_time/0Returns the current time, in seconds past midnight.
first_time/1Calculates the first time in a given period.
last_time/1Calculates the last time in a given period.
next_time/2Calculates the first time in the given period after the given time.
resolve_dow/1Returns the number of the given day of the week.
resolve_dur/1Returns seconds for a given duration.
resolve_period/1Returns a list of times given a periodic specification.
resolve_time/1Returns seconds past midnight for a given time.
run_task/1Spawns a process to accomplish the given task.
until_days_from_now/2Calculates the duration in seconds until the given period occurs several days from now.
until_next_daytime/1Calculates the duration in seconds until the next time this period is to occur during the day.
until_next_daytime_or_days_from_now/2Calculates the duration in seconds until the given period occurs, which may be today or several days from now.
until_next_time/1Calculates the duration in seconds until the next time a task is to be run.
until_tomorrow/1Calculates the duration in seconds until the given time occurs tomorrow.

Data Types

task() = {when(), mfa()}

mfa() = {module(), function(), args()}

when() = {daily, period()} | {weekly, dow(), period()} | {monthly, dom(), period()}

dow() = mon | tue | wed | thu | fri | sat | sun

dom() = integer()

period() = time() | [time()] | {every, duration(), constraint()}

duration() = {integer(), hr | min | sec}

constraint() = {between, time(), time()}

time() = {integer(), am | pm} | {integer(), integer(), am | pm}

Exported Functions

format_time/1

format_time(integer()) -> string()

Returns human-readable string from seconds past midnight.

loop_task/1

loop_task(task()) -> never_returns

Used by start/1 to wait until the next time each task is scheduled to run, run it, and repeat.

start/1

start([task()]) -> [pid()]

Starts crone, spawning a process for each task.

stop/1

stop([task()]) -> ok

Stops all monitoring processes started by crone.

Documented Internal Functions

current_time/0

current_time() -> seconds()

Returns the current time, in seconds past midnight.

first_time/1

first_time(period()) -> seconds()

Calculates the first time in a given period.

last_time/1

last_time(period()) -> seconds()

Calculates the last time in a given period.

next_time/2

next_time(period(), seconds()) -> seconds()

Calculates the first time in the given period after the given time.

resolve_dow/1

resolve_dow(dow()) -> integer()

Returns the number of the given day of the week. See the calendar module for day numbers.

resolve_dur/1

resolve_dur(duration()) -> seconds()

Returns seconds for a given duration.

resolve_period/1

resolve_period(period()) -> [seconds()]

Returns a list of times given a periodic specification.

resolve_time/1

resolve_time(time()) -> seconds()

Returns seconds past midnight for a given time.

run_task/1

run_task(task()) -> pid()

Spawns a process to accomplish the given task.

until_days_from_now/2

until_days_from_now(period(), integer()) -> seconds()

Calculates the duration in seconds until the given period occurs several days from now.

until_next_daytime/1

until_next_daytime(period()) -> seconds()

Calculates the duration in seconds until the next time this period is to occur during the day.

until_next_daytime_or_days_from_now/2

until_next_daytime_or_days_from_now(period(), integer()) -> seconds()

Calculates the duration in seconds until the given period occurs, which may be today or several days from now.

until_next_time/1

until_next_time(task()) -> seconds()

Calculates the duration in seconds until the next time a task is to be run.

until_tomorrow/1

until_tomorrow(seconds()) -> seconds()

Calculates the duration in seconds until the given time occurs tomorrow.