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

View File

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