We coded a scheduled job in an infinite loop with a 120 second sleep. The scheduled task is a ping on a website to get a tiny bit of data. What are the advantages/disadvantages of using a cron job over our solution?
Building a program that polls a remote site offers these problems/benefits,
- A defect (unhandled exception) and the program could fail, and stop polling
- A delay in the program could lead to time slipping (>120s delay)
- Separation of concerns - the scheduling of the polling mixed with program logic makes for more code (and more chances to fail)
- DRY - why (re)build cron functionality when it already exists
- Program must sit in memory even when it is not being used (1/120s)
Cron is built for periodic scheduling, here are some problems/benefits,
- Cron already built, and works, very reliable
- providing environment and logging output require care
- Child program must be restarted every 120s
- Cron does not check for other programs/servers/dependencies
- Cron does not signal/start downstream dependencies
- Cron does not offer tight scheduling constraints (neither sub-second, nor near-real-time)