This package allows you to run tasks at specified periods of time. Similar to ruby clockwork
gem.
Currently is under development.
- Add
ex_clockwork
to your list of dependencies inmix.exs
:
def deps do
[{:ex_clockwork, "~> 0.1.0"}]
end
- Ensure
ex_clockwork
is started before your application:
def application do
[applications: [:ex_clockwork]]
end
- Run generators to install sample schedule and handlers:
mix ex_clockwork.install
- Configure
ex_clockwork
application, 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.ex
file 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.ex
file 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 schedule
* Add examples
* Add tests
* Add moduledocs