Changeset 759


Ignore:
Timestamp:
Oct 26, 2015, 11:50:43 PM (9 years ago)
Author:
chronos
Message:
  • Fixed: Scheduler task can get to state where it was not scheduled after defined period.
  • Added: Log scheduler task last duration.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r758 r759  
    11<?php
    22
    3 $Revision = 758; // Subversion revision
    4 $DatabaseRevision = 755; // SQL structure revision
     3$Revision = 759; // Subversion revision
     4$DatabaseRevision = 759; // SQL structure revision
    55$ReleaseTime = strtotime('2015-10-26');
  • trunk/Common/Setup/Updates.php

    r757 r759  
    15771577  ADD CONSTRAINT `FinanceInvoiceStorno_ibfk_2` FOREIGN KEY (`StornoOf`) REFERENCES `FinanceInvoice` (`Id`);
    15781578  ");
     1579}
     1580
     1581function UpdateTo759($Manager)
     1582{
     1583  $Manager->Execute('ALTER TABLE `Scheduler` ADD `Duration` INT NOT NULL AFTER `Period`;');
    15791584}
    15801585
     
    16531658      748 => array('Revision' => 752, 'Function' => 'UpdateTo752'),
    16541659      752 => array('Revision' => 755, 'Function' => 'UpdateTo755'),
     1660      755 => array('Revision' => 759, 'Function' => 'UpdateTo759'),
    16551661    ));
    16561662  }
  • trunk/Modules/Scheduler/Scheduler.php

    r754 r759  
    2828        'Log' => array('Type' => 'Text', 'Caption' => 'Poslední záznam', 'Default' => '', 'ReadOnly' => true),
    2929        'LastExecutedTime' => array('Type' => 'DateTime', 'Caption' => 'Čas posledního spuštění', 'Default' => '', 'ReadOnly' => true),
     30        'Duration' => array('Type' => 'TimeDiff', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true),
    3031      ),
    3132    ));
     
    6465      $DbResult = $this->Database->query('SELECT `Scheduler`.*, `SchedulerAction`.`Class` AS `Class` FROM `Scheduler` '.
    6566        '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 '.
     67        'WHERE (`Scheduler`.`Enabled`=1) AND ( '.
     68        '(`Scheduler`.`ScheduledTime` < "'.TimeToMysqlDateTime(time()).'") OR '.
    6869        '(`Scheduler`.`ScheduledTime` IS NULL))');
    6970      while($DbRow = $DbResult->fetch_assoc())
     
    7172        echo('Executing '.$DbRow['Name']."\n");
    7273        $Output = '';
     74        $StartTime = time();
    7375        if(class_exists($DbRow['Class']))
    7476        {
     
    7779          echo($Output);
    7880        } else echo('Class '.$DbRow['Class'].' not found'."\n");
     81        $StopTime = time();
     82        $Duration = $StopTime - $StartTime;
    7983        $this->Database->update('Scheduler', 'Id='.$DbRow['Id'],
    80           array('Log' => $Output, 'LastExecutedTime' => 'NOW()'));
    81         if($DbRow['ScheduledTime'] == '') $NewScheduledTime = time() + $DbRow['Period'];
    82           else $NewScheduledTime = MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period'];
    83         if($DbRow['Period'] != '') $this->Database->update('Scheduler', 'Id='.$DbRow['Id'],
    84           array('ScheduledTime' => TimeToMysqlDateTime($NewScheduledTime)));
     84          array('Log' => $Output, 'LastExecutedTime' => TimeToMysqlDateTime($StartTime)));
     85        if($DbRow['Period'] != '') {
     86          if($DbRow['ScheduledTime'] == '') $NewScheduledTime = $StartTime + $DbRow['Period'];
     87            else $NewScheduledTime = MysqlDateTimeToTime($DbRow['ScheduledTime']) + $DbRow['Period'];
     88          if($NewScheduledTime < $StopTime) $NewScheduledTime = $StopTime + $DbRow['Period'];
     89          $this->Database->update('Scheduler', 'Id='.$DbRow['Id'],
     90            array('ScheduledTime' => TimeToMysqlDateTime($NewScheduledTime)));
     91        }
    8592      }
    8693      echo('.');
     
    96103  }
    97104}
     105
     106
     107class ScheduleTaskTest extends SchedulerTask
     108{
     109  function Execute()
     110  {
     111    $Output = '#';
     112    return($Output);
     113  }
     114}
Note: See TracChangeset for help on using the changeset viewer.