Why are there so many cron schedules on my site?

You might have installed some tool to find out what cron jobs are running on your site (like WP Crontrol or Debug Bar Cron). And you may have been alarmed to see something like this:

Even worse, they are set for every 5 minutes, so does that mean EWWW is running 5 tasks on your site every 5 minutes???

Fortunately, the answer is No. The important thing to note is these are merely schedules. The existence of a schedule does NOT mean any jobs actually run on that schedule. For example, if you have the Debug Bar Cron plugin, you would look at the Custom Events to see what is actually running.

So what are those schedules used for? They are used to schedule "health checks" for background image optimization. To understand that, we need to know a little more about how background processing works:

For example, say you upload 10 images, and EWWW IO begins adding them to the queue. It fires off an asynchronous (AJAX) request for each image to begin processing the images in the queue.

So, if background mode starts almost right away, what in the world is the 5 minute interval for, right? The background queue attempts to avoid PHP timeouts by terminating execution prior to reaching the max_execution_time setting. It then spawns a new process via asynchronous request. BUT, it isn't always successful, so the 5 minute cron job is a health check to make sure background processing finishes the queue. When that very first image is added to the queue, the plugin schedules a health check. If the images finish optimizing in under 5 minutes, the health check is cancelled and never runs. If the images take longer (say you uploaded 100 images instead of just 10), the health check will see if the process is still running. If it isn't running, and there are images left in the queue, it just kicks the process off again. This repeats until all the uploaded images are completed, and then the health check is completely removed.