johanna v0.1.4 Johanna
Simple wrapper for erlcron
,
the library providing testable cron like functionality for Erlang systems,
with the ability to arbitrarily set the time and place along
with fastforwarding through tests.
Examples (gracefully copy-pasted from original README
)
{{once, {3, 30, pm}},
{io, fwrite, ["Hello, world!~n"]}}
{{once, {12, 23, 32}},
{io, fwrite, ["Hello, world!~n"]}}
{{once, 3600},
{io, fwrite, ["Hello, world!~n"]}}
{{daily, {every, {23, sec}, {between, {3, pm}, {3, 30, pm}}}},
{io, fwrite, ["Hello, world!~n"]}}
{{daily, {3, 30, pm}},
fun() -> io:fwrite("It's three thirty~n") end}
{{daily, [{1, 10, am}, {1, 07, 30, am}]},
{io, fwrite, ["Bing~n"]}}
{{weekly, thu, {2, am}},
{io, fwrite, ["It's 2 Thursday morning~n"]}}
{{weekly, wed, {2, am}},
{fun() -> io:fwrite("It's 2 Wednesday morning~n") end}
{{weekly, fri, {2, am}},
{io, fwrite, ["It's 2 Friday morning~n"]}}
{{monthly, 1, {2, am}},
{io, fwrite, ["First of the month!~n"]}}
{{monthly, 4, {2, am}},
{io, fwrite, ["Fourth of the month!~n"]}}
Summary
Functions
Runs the given function recurrently at the time given
Cancels the job, previously started with at
/once
Runs the given function recurrently
Returns the DateTime
instance, currently set for erlcron
Sets the DateTime
instance for erlcron
. Useful in Timecop
-like scenarios
Sets the DateTime
instance for erlcron
on many nodes
Runs the given function every N
units (unit is :hr
, :min
or :sec
)
Runs the given function once
Replaces the job identified by reference (by cancelling the old one and placing the new one with the same reference)
Checks whether the job spec is valid
Functions
at(:erlcron.cron_time | :erlcron.seconds | Time.t, :erlcron.callable) :: :erlcron.job_ref
Runs the given function recurrently at the time given.
Examples
▶ Johanna.at({3, :pm}, fn -> IO.puts("¡Yay!") end)
▷ ... at 15:00, daily:
▷ "¡Yay!"
▶ Johanna.at({2, 45, :pm}, {IO, :puts, ["¡Yay!"]})
▷ ... at 14:45, daily:
▷ "¡Yay!"
Cancels the job, previously started with at
/once
.
Runs the given function recurrently.
Examples
▶ Johanna.cron({10, :am}, fn -> IO.puts("¡Yay!") end})
▷ ... at 10AM daily
▷ "¡Yay!"
Returns the DateTime
instance, currently set for erlcron
.
Examples
▶ Johanna.datetime()
▷ %DateTime{calendar: Calendar.ISO, day: 30, hour: 14, microsecond: {0, 0},
▷ minute: 2, month: 3, second: 43, std_offset: 0, time_zone: "Etc/UTC",
▷ utc_offset: 0, year: 2017, zone_abbr: "UTC"}
Sets the DateTime
instance for erlcron
. Useful in Timecop
-like scenarios.
Sets the DateTime
instance for erlcron
on many nodes.
every(Integer.t | :erlcron.duration, :erlcron.constraint | nil, :erlcron.callable) :: :erlcron.job_ref
Runs the given function every N
units (unit is :hr
, :min
or :sec
).
Examples
▶ Johanna.every(10, fn -> IO.puts("¡Yay!") end)
▷ ... every 10 secs
▷ "¡Yay!"
▶ Johanna.every({10, :sec}, fn -> IO.puts("¡Yay!") end)
▷ ... every 10 secs
▷ "¡Yay!"
▶ Johanna.every({1, :min}, {IO, :puts, ["¡Yay!"]})
▷ ... every 1 min
▷ "¡Yay!"
▶ Johanna.every(10, {:between, {1, :pm}, {4, :pm}}, fn -> IO.puts("¡Siesta!") end)
▷ ... every 10 secs from 1PM till 4PM
▷ "¡Siesta!"
once(:erlcron.cron_time | :erlcron.seconds | DateTime.t, :erlcron.callable) :: :erlcron.job_ref
Runs the given function once.
Examples
▶ Johanna.once(10, fn -> IO.puts("¡Yay!") end)
▷ ... 10 sec pause
▷ "¡Yay!"