mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
TaskScheduler: Remove repeating tasks which throw exceptions
This commit is contained in:
parent
6b4b4e4bb1
commit
02b4eeeb9b
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user