-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# CHANGELOG | ||
|
||
## v1 | ||
|
||
* Removed Helper Functions in Module `Crontab` | ||
* Moved `get_[next|previous]_run_dates` to `Crontab.Scheduler` | ||
* Renamed Modules to a better name | ||
* Introduction of `~e[CRON_EXPRESSION]` sigil | ||
* Renamed function to conventions. (`?` for booleans, `!` for functions that raise errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Usage Examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Basic Usage | ||
|
||
## Extended Cron expressions | ||
|
||
An extended cron expression has more precision then a normal cron expression. It also specifies the second. | ||
|
||
If you want to use extended cron expressions with the sigil, just append an `e`. | ||
|
||
## Checking if a Cron Expression Matches a date | ||
|
||
```elixir | ||
iex> import Crontab.CronExpression | ||
iex> Crontab.DateChecker.matches_date?(~e[*/2], ~N[2017-01-01 01:01:00]) | ||
false | ||
iex> Crontab.DateChecker.matches_date?(~e[*], ~N[2017-01-01 01:01:00]) | ||
true | ||
``` | ||
|
||
## Find Next / Previous Execution Date candidates | ||
|
||
All the date parameters default to now. | ||
|
||
For previous, just replace `next` in the code below. | ||
|
||
```elixir | ||
iex> import Crontab.CronExpression | ||
iex> Crontab.Scheduler.get_next_run_date(~e[*/2], ~N[2017-01-01 01:01:00]) | ||
{:ok, ~N[2017-01-01 01:02:00]} | ||
iex> Crontab.Scheduler.get_next_run_date!(~e[*/2], ~N[2017-01-01 01:01:00]) | ||
{:ok, ~N[2017-01-01 01:02:00]} | ||
``` | ||
|
||
```elixir | ||
iex> Crontab.Scheduler.get_next_run_dates(3, ~e[*/2], ~N[2017-01-01 01:01:00]) | ||
{:ok, | ||
[~N[2017-01-01 01:02:00], ~N[2017-01-01 01:04:00], ~N[2017-01-01 01:06:00]]} | ||
iex> Crontab.Scheduler.get_next_run_dates!(3, ~e[*/2], ~N[2017-01-01 01:01:00]) | ||
[~N[2017-01-01 01:02:00], ~N[2017-01-01 01:04:00], ~N[2017-01-01 01:06:00]] | ||
``` | ||
|
||
## Parse Cron Expressions | ||
|
||
If you statically define cron expressions, use the `~e[cron expression]` sigil. | ||
|
||
For dynamic cron expressions, there is a Parser module. | ||
|
||
The parser module takes an optional `extended` flag. This is to mark if the expression contains seconds. | ||
This defaults to `false`. | ||
|
||
```elixir | ||
iex> Crontab.CronExpression.Parser.parse "* * * * *" | ||
{:ok, | ||
%Crontab.CronExpression{day: [:*], hour: [:*], minute: [:*], | ||
month: [:*], weekday: [:*], year: [:*]}} | ||
iex> Crontab.CronExpression.Parser.parse! "* * * * *" | ||
%Crontab.CronExpression{day: [:*], hour: [:*], minute: [:*], | ||
month: [:*], weekday: [:*], year: [:*]} | ||
``` | ||
|
||
## Compose Cron expressions | ||
```elixir | ||
iex> Crontab.CronExpression.Composer.compose %Crontab.CronExpression{} | ||
"* * * * * *" | ||
iex> Crontab.CronExpression.Composer.compose %Crontab.CronExpression{minute: [9, {:-, 4, 6}, {:/, :*, 9}]} | ||
"9,4-6,*/9 * * * * *" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Getting Started | ||
## Installation | ||
|
||
1. Add `crontab` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:crontab, "~> 0.8.5"}] | ||
end | ||
``` | ||
|
||
2. Ensure `crontab` is started before your application: | ||
|
||
```elixir | ||
def application do | ||
[applications: [:crontab]] | ||
end | ||
``` | ||
|
||
## Import cron expression sigil | ||
Everywhere you want to use the cron expression sigil (`e[cron expression]`), import `Crontab.CronExpression`. | ||
|
||
```elixir | ||
import Crontab.CronExpression | ||
``` |