Changeset 738 for trunk/Modules/Scheduler/Scheduler.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Scheduler/Scheduler.php
r735 r738 13 13 $this->Dependencies = array(); 14 14 } 15 15 16 16 function DoStart() 17 17 { … … 34 34 'Table' => 'SchedulerAction', 35 35 'DefaultSortColumn' => 'Name', 36 36 'ReadOnly' => true, 37 37 'Items' => array( 38 38 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => '', 'ReadOnly' => true), … … 41 41 )); 42 42 $this->System->FormManager->RegisterFormType('TSchedulerAction', array( 43 44 45 46 47 43 'Type' => 'Reference', 44 'Table' => 'SchedulerAction', 45 'Id' => 'Id', 46 'Name' => 'Name', 47 'Filter' => '1', 48 48 )); 49 49 $this->System->RegisterCommandLine('run-scheduler', array('ModuleScheduler', 'Run')); 50 50 } 51 51 52 52 function DoInstall() 53 53 { … … 55 55 56 56 function DoUnInstall() 57 { 57 { 58 58 } 59 59 60 60 function Run() 61 { 62 while(true)63 64 65 66 67 ' (`Scheduler`.`LastExecutedTime` < `Scheduler`.`ScheduledTime`)) OR '.68 69 70 71 72 73 if(class_exists($DbRow['Class']))74 75 76 77 78 $this->Database->update('Scheduler', 'Id='.$DbRow['Id'], 79 80 81 else $NewScheduledTime = MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period']; 82 83 array('ScheduledTime' => TimeToMysqlDateTime($NewScheduledTime)));84 }85 86 87 61 { 62 while(true) 63 { 64 $DbResult = $this->Database->query('SELECT `Scheduler`.*, `SchedulerAction`.`Class` AS `Class` FROM `Scheduler` '. 65 'LEFT JOIN `SchedulerAction` ON `SchedulerAction`.`Id` = `Scheduler`.`Action` '. 66 'WHERE (`Scheduler`.`Enabled`=1) AND (((`Scheduler`.`ScheduledTime` < "'.TimeToMysqlDateTime(time()).'") AND '. 67 ' (`Scheduler`.`LastExecutedTime` < `Scheduler`.`ScheduledTime`)) OR '. 68 '(`Scheduler`.`ScheduledTime` IS NULL))'); 69 while($DbRow = $DbResult->fetch_assoc()) 70 { 71 echo('Executing '.$DbRow['Name']."\n"); 72 $Output = ''; 73 if(class_exists($DbRow['Class'])) 74 { 75 $Class = new $DbRow['Class']($this->System); 76 $Output = $Class->Execute(); 77 } else echo('Class '.$DbRow['Class'].' not found'."\n"); 78 $this->Database->update('Scheduler', 'Id='.$DbRow['Id'], 79 array('Log' => $Output, 'LastExecutedTime' => 'NOW()')); 80 if($DbRow['ScheduledTime'] == '') $NewScheduledTime = time() + $DbRow['Period']; 81 else $NewScheduledTime = MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period']; 82 if($DbRow['Period'] != '') $this->Database->update('Scheduler', 'Id='.$DbRow['Id'], 83 array('ScheduledTime' => TimeToMysqlDateTime($NewScheduledTime))); 84 } 85 echo('.'); 86 sleep(1); 87 } 88 88 } 89 89 } … … 91 91 class SchedulerTask extends Model 92 92 { 93 94 95 93 function Execute() 94 { 95 } 96 96 }
Note:
See TracChangeset
for help on using the changeset viewer.