function lassie_check

7.x lassie.module lassie_check($job_machine_name)
6.x lassie.module lassie_check($job_machine_name)

Check to see if an email needs to be sent regarding this job.

1 call to lassie_check()
lassie_check_all in modules/lassie/lassie.module
Check all of the jobs we are currently waiting on.

File

modules/lassie/lassie.module, line 77
This is the primary module file for the lassie module.

Code

function lassie_check($job_machine_name) {
  $job_machine_name = lassie_get_machine_name($job_machine_name);

  $data = variable_get('lassie_job__' . $job_machine_name, array());
  $start = $data ['start'];
  $elapsed = round((time() - $start) / 60, 3);
  $expires = $data ['expires'];
  if (time() > $expires) {
    // YES!  We need to trigger the email, this job has expired.
    $emails = $data ['emails'];
    // TODO: also include any default emails from settings.


    $hours = $data ['hours'];
    $user_uid = $data ['user_uid'];

    // TODO:  Implement a hook so other modules can act?


    // Implement the warning email.
    $msg = "";
    $msg .= "FlightPath Lassie module reports that a job has failed to complete in the expected time.\n\n";
    $msg .= "Current Time: " . format_date(convert_time(time())) . "\n-------------------------\n";
    $msg .= "Site: " . $GLOBALS ['fp_system_settings']["base_url"] . "\n";
    $msg .= "Job Name: $job_machine_name \n";
    $msg .= "Started: " . format_date(convert_time($start)) . "\n";
    $msg .= "Hours  : $hours \n";
    $msg .= "Expires: " . format_date(convert_time($expires)) . "\n";
    $msg .= "Elapsed: $elapsed min.";

    if ($emails != "") {
      fp_mail($emails, "FlightPath job failed to end: $job_machine_name", $msg);
    }

    // Delete from variables table.
    db_query("DELETE FROM variables WHERE name = ?", array("lassie_job__$job_machine_name"));
    watchdog('lassie', t("Expired job: ") . $job_machine_name . ". " . $elapsed . " minutes elapsed.", array(), WATCHDOG_ERROR);


    if (isset($GLOBALS ['lassie_disable_maintenance_mode_on_fail']) && $GLOBALS ['lassie_disable_maintenance_mode_on_fail'] == TRUE) {
      // We should set maintenance mode to FALSE.  See README.txt file for an explanation.
      variable_set("maintenance_mode", FALSE);
    }

  }

}