Move task timings responsibility from scheduler to handler

This commit is contained in:
Dylan K. Taylor 2018-05-30 15:38:39 +01:00
parent 51f43fb375
commit e20be3eeba
2 changed files with 7 additions and 4 deletions

View File

@ -48,7 +48,7 @@ class TaskHandler{
protected $cancelled = false;
/** @var TimingsHandler */
public $timings;
private $timings;
/** @var string */
private $taskName;
@ -161,7 +161,12 @@ class TaskHandler{
* @param int $currentTick
*/
public function run(int $currentTick){
$this->task->onRun($currentTick);
$this->timings->startTiming();
try{
$this->task->onRun($currentTick);
}finally{
$this->timings->stopTiming();
}
}
/**

View File

@ -189,14 +189,12 @@ class TaskScheduler{
unset($this->tasks[$task->getTaskId()]);
continue;
}else{
$task->timings->startTiming();
try{
$task->run($this->currentTick);
}catch(\Throwable $e){
$this->logger->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage());
$this->logger->logException($e);
}
$task->timings->stopTiming();
}
if($task->isRepeating()){
$task->setNextRun($this->currentTick + $task->getPeriod());