TaskScheduler: Remove repeating tasks which throw exceptions

This commit is contained in:
Dylan K. Taylor 2018-05-31 14:10:59 +01:00
parent 6b4b4e4bb1
commit 02b4eeeb9b

View File

@ -198,21 +198,28 @@ class TaskScheduler{
unset($this->tasks[$task->getTaskId()]); unset($this->tasks[$task->getTaskId()]);
continue; continue;
} }
$crashed = false;
try{ try{
$task->run($this->currentTick); $task->run($this->currentTick);
}catch(\Throwable $e){ }catch(\Throwable $e){
$crashed = true;
$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);
} }
if($task->isRepeating()){ if($task->isRepeating()){
if($crashed){
$this->logger->debug("Dropping repeating task " . $task->getTaskName() . " due to exceptions thrown while running");
}else{
$task->setNextRun($this->currentTick + $task->getPeriod()); $task->setNextRun($this->currentTick + $task->getPeriod());
$this->queue->insert($task, $this->currentTick + $task->getPeriod()); $this->queue->insert($task, $this->currentTick + $task->getPeriod());
}else{ continue;
}
}
$task->remove(); $task->remove();
unset($this->tasks[$task->getTaskId()]); unset($this->tasks[$task->getTaskId()]);
} }
} }
}
private function isReady(int $currentTick) : bool{ private function isReady(int $currentTick) : bool{
return count($this->tasks) > 0 and $this->queue->current()->getNextRun() <= $currentTick; return count($this->tasks) > 0 and $this->queue->current()->getNextRun() <= $currentTick;