I’d like to announce a new library I wrote recently for a project I’ve been working on. The library is called Citrine, it’s for managing and running scheduled jobs on an Erlang cluster as part of an existing application.
Summary: With Citrine you define a job, schedule it using cron syntax, and the library manages execution globally across the cluster to keep jobs running continuously. It’s designed to be used in stateless application environments such as Kubernetes.
# Create a job
job = %Citrine.Job{
id: "my_job_id",
schedule: "* * * * * *", # Run every second
task: job_task,
extended_syntax: true # Use extended cron syntax
}
# Start or update a job
MyApp.Scheduler.put_job(job)
# Terminate and delete a job
MyApp.Scheduler.delete_job(job)
Why I made this: I spent quite a bit of time looking into some of the existing libraries that existed, and none of them did exactly when I wanted, so I decided to build my own. It uses mnesia for state management, and mostly relies on Erlang primitives for everything. Thus, there are very few external dependencies (currently it only uses the crontab
library, which itself has almost zero dependencies).
Some other thoughts: I followed convention over configuration with this library. As such, there aren’t many options to change, and the API interface itself really only has 3 function (put a job, delete a job, and list jobs).