如何對 Drupal 的 cron 做 Debug

in

Drupal 的 cron 是個好用的東西, 但有時候出問題時也很難 debug, 當看到這幾個訊息時, 通常是上次的 cron 執行失敗了

Attempting to re-run cron while it is already running.
Cron run exceeded the time limit and was aborted.
Cron has been running for more than an hour and is most likely stuck.

在 variable 裡面, 有兩個相關參數, cron_last 是上次執行的時間, cron_semaphore 是代表 cron 正在執行. 所以如果執行 cron 的途中系統掛了, 可能就得手動清掉 semaphore, 不然即使你手動執行 cron, 系統也會回應已經有一個 cron 在執行了. 可用下列指令:

DELETE FROM variable WHERE name="cron_semaphore";

另外如果要看 cron 是執行到哪裡出問題了, 可修改 includes/module.inc

  foreach (module_implements($hook) as $module) {
    $function = $module .'_'. $hook;
    if ($hook == 'cron') watchdog('cron', "hit $module cron");   // add this line
    $result = call_user_func_array($function, $args);
    if (isset($result) && is_array($result)) {
      $return = array_merge($return, $result);
    }
    else if (isset($result)) {
      $return[] = $result;
    }
  }

執行結果如下, 可以看出 cron 執行到哪裡了.
Drupal cron



回應

發表新回應

這個欄位的內容會保密,不會公開顯示。
  • 自動將網址與電子郵件位址轉變為連結。
  • 可使用的 HTML 標籤:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • 自動斷行和分段。
  • Textual smileys will be replaced with graphical ones.

更多關於格式選項的資訊