You are here

function recommender_cron in Recommender API 6.2

Same name and namespace in other branches
  1. 6.3 recommender.module \recommender_cron()
  2. 7.6 recommender.module \recommender_cron()
  3. 7.3 recommender.module \recommender_cron()
  4. 7.4 recommender.module \recommender_cron()
  5. 7.5 recommender.module \recommender_cron()

File

./recommender.module, line 292

Code

function recommender_cron() {
  $last_cron = variable_get('recommender_last_cron', 0);
  $cron_freq = variable_get('recommender_cron_freq', 'never');
  $current = time();
  switch ($cron_freq) {
    case 'immediately':
      $run = TRUE;
      break;
    case 'hourly':
      $run = $current - $last_cron >= 3600 ? TRUE : FALSE;
      break;
    case 'every6hr':
      $run = $current - $last_cron >= 21600 ? TRUE : FALSE;
      break;
    case 'every12hr':
      $run = $current - $last_cron >= 43200 ? TRUE : FALSE;
      break;
    case 'daily':
      $run = $current - $last_cron >= 86400 ? TRUE : FALSE;
      break;
    case 'weekly':
      $run = $current - $last_cron >= 604800 ? TRUE : FALSE;
      break;
    case 'never':
    default:
      $run = FALSE;
  }
  $msg = $run ? "Will run." : "Not running.";
  watchdog('recommender', "Recommender cron at frequency {$cron_freq}. {$msg}");
  if ($run == TRUE) {
    recommender_run();
    variable_set('recommender_last_cron', $current);
  }
}