We Don’t Run Cron Jobs (2016)
That was a difficult read for me, the blog post starts out with the four main problems with cron (their use wasn&#x27;t scalable, editing the text file was hard, running their jobs are complex, and they didn&#x27;t have any telemetry.)<p>That&#x27;s great, what does that have to do with cron?<p>As a result what I read was:<p>&quot;We don&#x27;t understand what cron does, nor do we understand how job scheduling is supposed to work, and we don&#x27;t understand how to write &#x27;service&#x27; based applications, so somebody said &#x27;Just use cron&#x27; and we did some stuff and it didn&#x27;t work how we liked, and we still haven&#x27;t figured out really what is going on with schedulers so we wrote our own thing which works for us but we don&#x27;t have any idea why something as broken as cron has persisted as the way to do something for longer than any of us has been alive.&quot;<p>I&#x27;m not sure that is the message they wanted to send. So lets look at their problems and their solution for a minute and figure out what is really going on here.<p>First problem was &#x27;scalability&#x27;. Which is described in the blog post as &quot;cron jobs pushed the machine to its limit&quot; and their scalability solution was to write a program that put a layer between the starting of the jobs and the jobs themselves (sends messages to SQS) and they used a new scheduler (AP scheduler to implement the core scheduler).<p>So what was the real win here? (since they have recreated cron :-)) The win is that instead of forking and execing as cron does allowing things like standard in and what not to be connected to the process, their version of cron sends a message to another system to actually start jobs. Guess what, if they wrote a bit of python code that all it did was send a message to SQS and exit that would run pretty simply. If they did it in C or C++ so they weren&#x27;t loading an entire interpreter and its run time everytime it would be lighting fast and add no load to the &quot;cron server&quot;, this is basically being unaware of how cron works so not knowing what would be the best way to use it.<p>Their second beef was that cron tabs are hard to edit reliably. Their solution was to write a giant CGI script in a web server that would read in the data structure used by their scheduler for jobs, show it as a web page, let people make changes to it, and then re-write the updated data structure to the scheduler. Guess what, the cron tab is just the data structure for cron in a text form so you can edit it by hand if necessary. Or you can use crontab -e which does syntax checking, or you could even write a giant CGI script that would read in the cron file, display it nicely on a web page, and then re-write as syntactically correct cron tab when it was done.<p>Problem three was that their jobs were complex and <i>failed often</i>. This forced their poor opsen to log in, cut and paste a complex command line and restart the job. The real problem there is <i>jobs are failing</i> which is going to require someone to figure out why they failed. If you don&#x27;t give a crap about why they failed the standard idiom is a program that forks the child to do the thing you want done and if you catch a signal from it that it has died you fork it again[1]. But really what is important here is that you have a configuration file <i>under source code control</i> that contains the default parameters for the jobs you are running so that starting them is just typing in the jobname if you need to restart or maybe overriding a parameter like a disk that is too full if that is why it failed. Again, nothing to do with cron and everything to do with writing code that runs on servers.<p>And finally their is no telemetry, no way to tell what is going on. Except that UNIX and Linux have like a zillion ways to get telemetry out, the original one is syslog, where jobs can send messages that get collected over the network even, of what they are up to, how they are feeling and what, if anything, is going wrong. There are even different levels like INFO, or FATAL which tell you which ones are important. Another tried and true technique is to dump a death rattle into &#x2F;tmp for later collection by a mortician process (also scheduled by cron).<p>At the end of the day, I can&#x27;t see how <i>cron</i> had anything to do with their problems, their inability to understand the problem they were trying to solve in a general way which would have allowed them to see many solutions, both with cron or with other tools that solve similar problems, would have saved them from re-inventing the wheel yet again, giving them the opportunity to experience the bugs that those other systems have fixed given their millions (if not billions) of hours of collective run time.<p>[1] Yes this is lame and you get jobs that just loop forever restarting again and again which is why the <i>real</i> problem is the failing not the forking.