mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Remove TaskHandler dependency on MainLogger
This instead allows the exception to be caught by the scheduler and reported using its logger.
This commit is contained in:
parent
e20be3eeba
commit
a8c766be88
@ -25,7 +25,6 @@ namespace pocketmine\scheduler;
|
|||||||
|
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\timings\TimingsHandler;
|
use pocketmine\timings\TimingsHandler;
|
||||||
use pocketmine\utils\MainLogger;
|
|
||||||
|
|
||||||
class TaskHandler{
|
class TaskHandler{
|
||||||
|
|
||||||
@ -145,8 +144,6 @@ class TaskHandler{
|
|||||||
if(!$this->isCancelled()){
|
if(!$this->isCancelled()){
|
||||||
$this->task->onCancel();
|
$this->task->onCancel();
|
||||||
}
|
}
|
||||||
}catch(\Throwable $e){
|
|
||||||
MainLogger::getLogger()->logException($e);
|
|
||||||
}finally{
|
}finally{
|
||||||
$this->remove();
|
$this->remove();
|
||||||
}
|
}
|
||||||
|
@ -106,14 +106,19 @@ class TaskScheduler{
|
|||||||
*/
|
*/
|
||||||
public function cancelTask(int $taskId){
|
public function cancelTask(int $taskId){
|
||||||
if($taskId !== null and isset($this->tasks[$taskId])){
|
if($taskId !== null and isset($this->tasks[$taskId])){
|
||||||
|
try{
|
||||||
$this->tasks[$taskId]->cancel();
|
$this->tasks[$taskId]->cancel();
|
||||||
|
}catch(\Throwable $e){
|
||||||
|
$this->logger->critical("Task " . $this->tasks[$taskId]->getTaskName() . " threw an exception when trying to cancel: " . $e->getMessage());
|
||||||
|
$this->logger->logException($e);
|
||||||
|
}
|
||||||
unset($this->tasks[$taskId]);
|
unset($this->tasks[$taskId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancelAllTasks(){
|
public function cancelAllTasks(){
|
||||||
foreach($this->tasks as $task){
|
foreach($this->tasks as $id => $task){
|
||||||
$task->cancel();
|
$this->cancelTask($id);
|
||||||
}
|
}
|
||||||
$this->tasks = [];
|
$this->tasks = [];
|
||||||
while(!$this->queue->isEmpty()){
|
while(!$this->queue->isEmpty()){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user