Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbernardo95/cronex
A cron like system built in Elixir, that you can mount in your supervision tree
https://github.com/jbernardo95/cronex
cron cron-jobs elixir
Last synced: about 1 month ago
JSON representation
A cron like system built in Elixir, that you can mount in your supervision tree
- Host: GitHub
- URL: https://github.com/jbernardo95/cronex
- Owner: jbernardo95
- License: mit
- Created: 2016-10-17T21:33:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-16T15:28:08.000Z (over 3 years ago)
- Last Synced: 2024-10-01T15:43:53.252Z (2 months ago)
- Topics: cron, cron-jobs, elixir
- Language: Elixir
- Homepage: https://hex.pm/packages/cronex
- Size: 71.3 KB
- Stars: 48
- Watchers: 2
- Forks: 12
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Cron like system you can mount in your supervision tree. (Date and Time)
- fucking-awesome-elixir - cronex - Cron like system you can mount in your supervision tree. (Date and Time)
- awesome-elixir - cronex - Cron like system you can mount in your supervision tree. (Date and Time)
README
# Cronex
[![Travis Build](https://api.travis-ci.org/jbernardo95/cronex.svg?branch=master)](https://travis-ci.org/jbernardo95/cronex/)
A cron like system, built in Elixir, that you can mount in your supervision tree.
Cronex's DSL for adding cron jobs is inspired by [whenever](https://github.com/javan/whenever) Ruby gem.
## Installation
Add `cronex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:cronex, "~> 0.4.0"}]
end
```Then run `mix deps.get` to get the package.
## Getting started
Cronex makes it really easy and intuitive to schedule cron like jobs.
You use the `Cronex.Scheduler` module to define a scheduler and add jobs to it.
Cronex will gather jobs from the scheduler you defined and will run them at the expected time.
```elixir
# Somewhere in your application define your scheduler
defmodule MyApp.Scheduler do
use Cronex.Schedulerevery :hour do
IO.puts "Every hour job"
endevery :day, at: "10:00" do
IO.puts "Every day job at 10:00"
end
end# Start scheduler with start_link
MyApp.Scheduler.start_link# Or add it to your supervision tree
defmodule MyApp.Supervisor do
use Supervisor# ...
def init(_opts) do
children = [
# ...
supervisor(MyApp.Scheduler, [])
# ...
]supervise(children, ...)
end# ...
end
```You can define as much schedulers as you want.
## Testing
Cronex comes with `Cronex.Test` module which provides helpers to test your cron jobs.
```elixir
defmodule MyApp.SchedulerTest do
use ExUnit.Case
use Cronex.Testtest "every hour job is defined in MyApp.Scheduler" do
assert_job_every :hour, in: MyApp.Scheduler
endtest "every day job at 10:00 is defined in MyApp.Scheduler" do
assert_job_every :day, at: "10:00", in: MyApp.Scheduler
end
end
```## Documentation
The project documentation can be found [here](https://hexdocs.pm/cronex/api-reference.html).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jbernardo95/cronex.
## License
Cronex source code is licensed under the [MIT License](LICENSE.md).