Skip to content

Commit

Permalink
Merge pull request #60 from saleyn/master
Browse files Browse the repository at this point in the history
Fix several bugs

Rewrite of core
  • Loading branch information
Santiniis authored Nov 16, 2019
2 parents b119bf3 + 511e56b commit 879d45c
Show file tree
Hide file tree
Showing 14 changed files with 1,265 additions and 639 deletions.
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
sudo: false
language: erlang
otp_release:
- R15B03
- R16B03-1
- 17.5
- 18.0
- 18.1
- 19.0
- 20.0
- 21.0
- 22.0

before_script: "make get-deps"
script: "make test"
Expand Down
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ does. Each job is assigned to a single (Erlang) process. The time
until it is to run next is calculated, and the process sleeps for
exactly that long.

Unlike cron's one-minute resolution, erlcron has a 2-second resolution
(actually 1 second, but after running the job, the process waits an
extra second to avoid accidentally running it more than once.)
Unlike cron's one-minute resolution, erlcron has a millisecond resolution.

It does not handle Daylight Savings Time (or other cases when the
system clock is altered) gracefully, and it is recommended that it be
stopped and restarted on such occasions.
It does handle Daylight Savings Time changes (but not the cases when the
system clock is altered by small increments, in which case the next
execution of a scheduled task may be imprecise).

Cron Job Description Examples:

```erlang
{{once, {3, 30, pm}, fun() -> io:fwrite("Hello world!~n") end}

{{once, {3, 30, pm}, fun(JobRef, CurrDateTime) -> io:fwrite("Hello world!~n") end}

{{once, {3, 30, pm}},
{io, fwrite, ["Hello, world!~n"]}}

Expand All @@ -54,14 +56,30 @@ Cron Job Description Examples:
{{weekly, wed, {2, am}},
{fun() -> io:fwrite("It's 2 Wednesday morning~n") end}

{{weekly, [tue,wed], {2, am}},
{fun(_, Now) -> io:format("Now is ~p~n", [Now]) 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, [1, 7, 14], {2, am}},
{io, fwrite, ["Every 1st, 7th, 14th of the month!~n"]}}

{{monthly, 0, {2, am}},
{io, fwrite, ["Last day of the month!~n"]}}

{{monthly, [0, -1], {2, am}},
{io, fwrite, ["Last two days of the month!~n"]}}

{{monthly, 4, {2, am}},
{io, fwrite, ["Fourth of the month!~n"]}}

%% Days of month less or equal to zero are subtracted from the end of the month
{{monthly, 0, {2, am}},
{io, fwrite, ["Last day of the month!~n"]}}
```

Adding a cron to the system:
Expand All @@ -73,15 +91,21 @@ Job = {{weekly, thu, {2, am}},
erlcron:cron(Job).
```

Cron jobs can be given named atom references:

```erlang
erlcron:cron(test_job1, {{once, {3,pm}}, {io, fwrite, "It's 3pm"}}).
```

A simple way to add a daily cron:

erlcron:at({3, 30, pm}, Fun).
erlcron:daily({3, 30, pm}, Fun).

A simple way to add a job that will be run once in the future. Where
'once' is the number of seconds until it runs.

```erlang
erlcron:once(300, Fun).
erlcron:at(300, Fun).
```

Cancel a running job.
Expand All @@ -90,7 +114,7 @@ Cancel a running job.
erlcron:cancel(JobRef).
```

Get the current date time of the system.
Get the current reference (univeral) date time of the system.

```erlang
erlcron:datetime().
Expand Down
6 changes: 2 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
%% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*-
%% Dependencies ================================================================
{deps, [{rebar_vsn_plugin, ".*",
{git, "https://github.com/erlware/rebar_vsn_plugin.git",
{tag, "master"}}}]}.
{deps, []}.

%% Rebar Plugins ==============================================================
{plugins, [rebar_vsn_plugin]}.
{plugins, []}.

%% Compiler Options ============================================================
{erl_opts,
Expand Down
Loading

0 comments on commit 879d45c

Please sign in to comment.