Changeset 12443

Show
Ignore:
Timestamp:
02/14/08 11:32:03 (11 months ago)
Author:
pottedmeat
Message:

Refs #5602. Make cron runs time-based

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • util/branches/dev/jsdoc/jsdoc.module

    r12442 r12443  
    390390} 
    391391 
     392function _jsdoc_cron_timeout(){ 
     393  static $start; 
     394  static $count; 
     395  if (!$start) { 
     396    $start = time(); 
     397    return false; 
     398  } 
     399  ++$count; 
     400  $delta = time() - $start; 
     401  $avg = $delta / $count; 
     402  $estimate = $delta + $avg; 
     403  if ($estimate > 30) { 
     404    return true; 
     405  } 
     406  return false; 
     407} 
     408 
    392409/** 
    393410 * Implementation of hook_cron(). 
     
    409426  // Use the configuration settings to switch directories, and load the plugin file 
    410427  _jsdoc_cron_chdir(true); 
     428  _jsdoc_cron_timeout(); 
    411429 
    412430  // Validate the stuff added in the newly included file 
    413431  if (_jsdoc_cron_validate_include()) { 
    414432    $files = variable_get('jsdoc_cron_files', array()); 
    415     $limit = 25; 
    416433    if (!empty($files)) { 
    417434      call_user_func(_jsdoc_base() . '_get_files'); 
     
    426443    } 
    427444 
    428     if(count($files) <= $limit){ 
    429       variable_set('jsdoc_cron_files', array()); 
    430     }else{ 
    431       variable_set('jsdoc_cron_files', array_slice($files, $limit)); 
    432     } 
    433  
    434445    if (!is_array($files)) { 
    435446      watchdog('jsdoc', _jsdoc_base() . '_get_files' . t(' does not return an array in ') . _jsdoc_file_location(), WATCHDOG_ERROR); 
     
    449460 
    450461      $count = 0; 
    451       foreach ($files as $list) { 
    452         if($count == $limit){ 
     462      while (count($files)) { 
     463        $list = array_shift($files); 
     464 
     465        if (_jsdoc_cron_timeout()) { 
    453466          break; 
    454467        } 
     468        else{ 
     469          variable_set('jsdoc_cron_files', $files); 
     470          if (empty($files)) { 
     471            break; 
     472          } 
     473        } 
     474 
    455475        ++$count; 
    456476        list($namespace, $file_name) = $list; 
     
    560580          } 
    561581        } 
     582 
     583        $files = variable_get('jsdoc_cron_files', array()); 
    562584      } 
    563585