While implementing scheduling tasks in naturally asynchronous environments like Erlang and Elixir is straightforward, building a reliable and efficient solution requires careful consideration.
Ecron supports both cron-style and interval-based job scheduling, focusing on resiliency, correctness, and lightweight with comprehensive testing via PropTest.
Use Case
Ecron’s precise scheduling is perfect for:
Security: 0 3 * * 0 Rotate API keys and dynamic credentials automatically every Sunday at 3 AM
Flash Sale: 0 8 * * * Launch flash sales with precision at 8 AM
Analytics: 0 9 * * 1 Sending comprehensive weekly reports every Monday at 9 AM
Disk Protection: 30 23 * * * Compress and archive old logs at 23:30 daily
Data Cleanup: 0 1 1 * * Pruning inactive users on the first day of each month
Data Backup: 0 2 * * * Create reliable Mnesia database backups every day at 2 AM
The two libraries, Ecron and Quantum-Core, have some differences in their job option APIs:
Overlap Check Support
Both libraries allow overlap checks to prevent jobs from running concurrently. In Ecron, this is configured using singleton: true, while in Quantum-Core, it’s set with overlap: true.
Additional Options in Ecron
Ecron provides extra configuration options that Quantum-Core does not offer:
max_runtime_ms: pos_integer() | unlimited
Defines the maximum runtime per execution in milliseconds. Default is unlimited.
start_time: {Hour, Min, Sec} | unlimited
Specifies the start time for job execution. Default is unlimited.
end_time: {Hour, Min, Sec} | unlimited
Specifies the end time for job execution. Default is unlimited.
max_count: pos_integer() | unlimited
Sets the maximum number of times a job can execute. Once this limit is reached, the job is automatically removed. Default is unlimited.
Run Strategy Differences
Quantum-Core’s run_strategy supports multiple options: All, Local, Node_list, and Random, offering flexibility in how jobs are distributed across nodes. Ecron, on the other hand, only supports :local and :global, limiting its distribution options.
Recommendation
If your project is already using Quantum-Core and running smoothly, there’s no need to switch—stick with it.
For new projects, you might consider giving Ecron a try, especially if its additional options align with your needs.
Internal Implementation Differences
The two libraries also differ significantly in their internal design:
In Quantum-Core, all tasks track in JobBroadcaster(GenStage), then notifies execution of task to ExecutionBroadcaster. This design elegantly implements the above run_strategies.
Ecron adopts a model similar to the standard library’s timer, where multiple tasks can share a single process, potentially improving efficiency. For more details, you can check out this blog post.
Thank you for your excellent suggestion. However, I don’t intend to delve into comparisons between different libraries. In my view, it might not be necessary to contrast other libraries within the documentation. It would be sufficient for the documentation to clearly articulate its own functionalities.