function radioactivity_cron in Radioactivity 5
Same name and namespace in other branches
- 8.3 radioactivity.module \radioactivity_cron()
- 8.2 radioactivity.module \radioactivity_cron()
- 6 radioactivity.module \radioactivity_cron()
- 7.2 radioactivity.module \radioactivity_cron()
- 7 radioactivity.module \radioactivity_cron()
- 4.0.x radioactivity.module \radioactivity_cron()
File
- ./
radioactivity.module, line 455
Code
function radioactivity_cron() {
if (radioactivity_get_memcached_enable()) {
radioactivity_process_memcached_entries();
}
$timestamp = time();
// last cron
$last_cron_timestamp = (int) variable_get('radioactivity_last_cron_timestamp', 0);
$granularity = (int) _radioactivity_get_decay_granularity();
$threshold_timestamp = $last_cron_timestamp - $last_cron_timestamp % $granularity + $granularity;
if ($timestamp < $threshold_timestamp) {
return;
}
// don't update yet
foreach (_radioactivity_get_decay_profiles() as $dpid => $decay_profile) {
$half_life = (double) $decay_profile["half_life"];
$cut_off_energy = (double) $decay_profile["cut_off_energy"];
// the formula is:
// E=E_0 * 2^(- delta_time / half_life)
db_query("UPDATE {radioactivity} SET energy=energy * pow(2, (last_emission_timestamp-%d)*1.0/%f), last_emission_timestamp=%d " . "WHERE decay_profile=%d AND last_emission_timestamp<%d", $timestamp, $half_life, $timestamp, $dpid, $timestamp);
// delete clean (l. non-radioactive) nodes
db_query("DELETE FROM {radioactivity} WHERE decay_profile=%d AND energy < %f", $dpid, $cut_off_energy);
}
variable_set('radioactivity_last_cron_timestamp', $timestamp);
}