Skip to content

Commit

Permalink
docs: update readme add motivation and more samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Oct 14, 2018
1 parent 7adc9db commit ab69b2e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Every

Generate at rounded intervals for `Process.send_after/3`.
Generate at even intervals for `Process.send_after/3`.
Sometimes we need to have periodic tasks to execute exactly at
certain intervals, for example run task every 15 minutes within hour
so we want to execute our task

1. At the beginning of hour,
2. 15th minute,
3. 30th minute,
4. 45th minute.

So instead of doing it manually it is better if it automated.

## Usage

Expand All @@ -20,6 +30,22 @@ then makes all calculation relative to given `DateTime` struct.
optional parameter `relative_to` if provided then makes all calculation relative to
given `DateTime` struct. First argument is literally to be read as `Every N minutes/hours`.

All methods return duration in seconds so it is your task to turn secons into milleseconds etc.

### How to use with periodic tasks

```ex
# Lets say we want to trigger our task every 5 minutes and current time is 12:02
# so next call will be at 12:05, 12:10 ... 12:55 ...
Process.send_after(self(), :work, Every.minutes(5) * 1000)

# If we want to trigger every minute
Process.send_after(self(), :work, Every.minute() * 1000)

# If we want to trigger every hour
Process.send_after(self(), :work, Every.hour() * 1000)
```

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
Expand Down

0 comments on commit ab69b2e

Please sign in to comment.