mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Move task timings responsibility from scheduler to handler
This commit is contained in:
parent
51f43fb375
commit
e20be3eeba
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user