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,19 +198,26 @@ class TaskScheduler{
unset($this->tasks[$task->getTaskId()]);
continue;
}
$crashed = false;
try{
$task->run($this->currentTick);
}catch(\Throwable $e){
$crashed = true;
$this->logger->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage());
$this->logger->logException($e);
}
if($task->isRepeating()){
$task->setNextRun($this->currentTick + $task->getPeriod());
$this->queue->insert($task, $this->currentTick + $task->getPeriod());
}else{
$task->remove();
unset($this->tasks[$task->getTaskId()]);
if($crashed){
$this->logger->debug("Dropping repeating task " . $task->getTaskName() . " due to exceptions thrown while running");
}else{
$task->setNextRun($this->currentTick + $task->getPeriod());
$this->queue->insert($task, $this->currentTick + $task->getPeriod());
continue;
}
}
$task->remove();
unset($this->tasks[$task->getTaskId()]);
}
}