diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-10-19 05:22:51 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-10-19 05:22:51 +0300 |
commit | c70b9bc89c167082b0891d3d44068f5b8f57831b (patch) | |
tree | 317d1dbe37be42df2632cd5c0518eeb99aa015d4 /lib/Model | |
parent | fcb80397d410a8c275b911cbbec5dfa5ce60b32e (diff) |
improvement on the tick managment
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/Runner.php | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 8644dd9..a2187aa 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -37,10 +37,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Runner { + const TICK_TTL = 1800; - const TICK_TTL = 300; const TICK_MINIMUM = 2; - const MEMORY_INFO_UPDATE = 5; + const TICK_UPDATE = 10; + const MEMORY_UPDATE = 5; const RESULT_TYPE_SUCCESS = 1; const RESULT_TYPE_WARNING = 4; @@ -74,7 +75,10 @@ class Runner { private $oldAction = ''; /** @var int */ - private $ramTick = 0; + private $ramUpdate = 0; + + /** @var int */ + private $tickUpdate = 0; /** @var array */ private $methodOnKeyPress = []; @@ -175,14 +179,10 @@ class Runner { } $this->setInfo('action', $action); - try { - $this->runningService->update($this->tickId, $action); - } catch (TickIsNotAliveException $e) { - $this->output('Force Quit'); - exit(); - } - $this->updateTick($tick); + $this->updateTick($tick, $action); + $this->updateRamInfo($tick); + $this->oldAction = $action; $this->oldTick = $tick; @@ -290,9 +290,7 @@ class Runner { $this->methodOnInfoUpdate[] = $method; } - /** - * @param $key - */ + public function infoUpdated() { foreach ($this->methodOnInfoUpdate as $method) { call_user_func($method, $this->info); @@ -367,15 +365,37 @@ class Runner { /** + * @param int $tick + * @param string $action + * + * @throws TickDoesNotExistException + */ + private function updateTick($tick, $action) { + if ($this->oldAction === $action && ($this->tickUpdate + self::TICK_UPDATE > $tick)) { + return; + } + + try { + $this->runningService->update($this->tickId, $action); + } catch (TickIsNotAliveException $e) { + $this->output('Force Quit'); + exit(); + } + + $this->tickUpdate = $tick; + } + + + /** * @param $tick */ - private function updateTick($tick) { - if (($this->ramTick + self::MEMORY_INFO_UPDATE) > $tick) { + private function updateRamInfo($tick) { + if (($this->ramUpdate + self::MEMORY_UPDATE) > $tick) { return; } $this->setInfo('_memory', round((memory_get_usage() / 1024 / 1024)) . ' MB'); - $this->ramTick = $tick; + $this->ramUpdate = $tick; } @@ -461,4 +481,4 @@ class Runner { } -}
\ No newline at end of file +} |