Web design, programming, graphics, and pretty much anything else I care about.

Update email send time always incremented by one cron run

I enabled the update feature that emails me whenever the site has an update available. I noticed that the time the email gets sent is always incremented by one cron run. For example, I have cron running hourly, so if there are updates needed it will email me at 8am, the next day at 9am, the next day at 10am, etc. But, based on the math, whatever interval cron runs at the email will likely always be one run later.

In hook_cron, the if statement requires the current time to be greater than interval (in my case, 24hrs). If it is exactly 24hrs, it will not pass.

<?php
function update_cron() {
 
$frequency = variable_get('update_check_frequency', 1);
 
$interval = 60 * 60 * 24 * $frequency;
 
// Cron should check for updates if there is no update data cached or if the
  // configured update interval has elapsed.
 
if (!_update_cache_get('update_available_releases') || ((time() - variable_get('update_last_check', 0)) > $interval)) {
   
update_refresh();
   
_update_cron_notify();
  }
}
?>

Also, 'update_last_check' is set in _update_refresh(), after some work is done. You only need enough time between a cron run and the setting of 'update_last_check' for a second to turn over to guarantee this not running at the same time.

In my install, I moved the variable_set for 'update_last_check' from _update_refresh() to the first thing inside this if, and change the operator to >= (as the difference more often ends up exactly zero). It has been working for several days, sending the update email at the same time.

(On a side note, it would be nice if there was a setting to say exactly when to send email updates.)

I posted an issue about this. http://drupal.org/node/1137628