named tasks in leader_cron
Jan 12, 2013 23:35 · 138 words · 1 minute read
I’ve been using erlcron to run scheduled tasks, but since each node in an erlang cluster would have its own copy, it didn’t help with having the tasks run in only one location per-cluster. Then I found leader_cron, which uses gen_leader to elect a single node in the cluster to run the tasks.
This is great stuff, but it doesn’t solve the problem of which node should schedule the task. For this purpose, I added the feature of named tasks, so that if you add a task with the same name, you receive a {error, already_exists} response. This way all the nodes can try to schedule the tasks, but only one will succeed.
I’ve submitted it to the maintainer and I hope he likes it, but it seems useful enough to hold onto even if he has reservations.