ExClockwork
This package allows you to run tasks at specified periods of time. Similar to ruby clockwork gem.
Currently is under development.
Installation
-
Add
ex_clockworkto your list of dependencies inmix.exs:
```elixir
def deps do
[{:ex_clockwork, "~> 0.1.0"}]
end
```-
Ensure
ex_clockworkis started before your application:
```elixir
def application do
[applications: [:ex_clockwork]]
end
```- Run generators to install sample schedule and handlers:
```elixir
mix ex_clockwork.install
```-
Configure
ex_clockworkapplication, at config/config.exs:config :ex_clockwork, schedule: ExBlog.Schedule, interval: 1000
`schedule` - module with tasks definitions
`interval` - parameters sets tick interval, by default it is 1 second, so ex_clockwork will check every second if it has tasks to do.-
Configure
schedule.exfile to add your custom tasks:defmodule MyApp.Schedule do use ExClockwork.Schedule every(2, :second, MyApp.MyEventHandler) end
first parameter - period of your task
second - measurement, e.g. `:second`, `:minute`, `:hour`
third - module name, that will be triggered when the period is finished-
Customize
my_event_handler.exfile or create a custom one with definition of work that will be done periodically:defmodule MyApp.MyEventHandler do use ExClockwork.Handler def run do # do anything here end end
run method of this module will be invoked every 2 seconds, as defined in scheduleTODO
* Add examples
* Add tests
* Add moduledocs