From 4d69d4bfaf606bf842fc6bd6b88460c3f6254388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 29 Mar 2021 10:40:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Crontab/ZookeeperProcess.php | 93 +++++++++++++++-------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/System/Crontab/ZookeeperProcess.php b/System/Crontab/ZookeeperProcess.php index b2e747f3..d562ad98 100644 --- a/System/Crontab/ZookeeperProcess.php +++ b/System/Crontab/ZookeeperProcess.php @@ -24,65 +24,68 @@ class ZookeeperProcess extends Process { - private Channel $channel; - private WaitGroup $waitGroup; + private Channel $channel; + private WaitGroup $waitGroup; - /** @var Crontab[] $names */ - public array $names = []; + /** @var Crontab[] $names */ + public array $names = []; - public array $scores = []; - public array $timers = []; + public array $scores = []; + public array $timers = []; - /** - * @param \Swoole\Process $process - * @throws ReflectionException - * @throws ComponentException - * @throws NotFindClassException - */ - public function onHandler(\Swoole\Process $process): void - { - $crontab = Snowflake::app()->get('crontab'); - $crontab->clearAll(); + /** + * @param \Swoole\Process $process + * @throws ReflectionException + * @throws ComponentException + * @throws NotFindClassException + * @throws Exception + */ + public function onHandler(\Swoole\Process $process): void + { + $crontab = Snowflake::app()->get('crontab'); + $crontab->clearAll(); - $process->name('Crontab zookeeper.'); - Timer::tick(1000, function () { - $startTime = time(); + if (Snowflake::getPlatform()->isLinux()) { + $process->name('Crontab zookeeper.'); + } + Timer::tick(1000, function () { + $startTime = time(); - $redis = Snowflake::app()->getRedis(); + $redis = Snowflake::app()->getRedis(); - $range = $redis->zRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime); - $redis->zRemRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime); + $range = $redis->zRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime); + $redis->zRemRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime); - /** @var Consumer $consumer */ - $consumer = Snowflake::app()->get(Consumer::class); + /** @var Consumer $consumer */ + $consumer = Snowflake::app()->get(Consumer::class); - foreach ($range as $value) { - $consumer->write('crontab:' . md5($value)); - } - $redis->release(); - }); - } + foreach ($range as $value) { + $consumer->write('crontab:' . md5($value)); + } + $redis->release(); + }); + } - /** - * @param string $name - */ - public function clear(string $name) - { - if (!isset($this->names[$name])) { - return; - } - $timers = $this->timers[$name]; + /** + * @param string $name + */ + public function clear(string $name) + { + if (!isset($this->names[$name])) { + return; + } + $timers = $this->timers[$name]; - $search = array_search($name, $this->scores[$timers]); - if ($search !== false) { - unset($this->scores[$timers][$search]); - } - unset($this->timers[$name], $this->names[$name]); - } + $search = array_search($name, $this->scores[$timers]); + if ($search !== false) { + unset($this->scores[$timers][$search]); + } + unset($this->timers[$name], $this->names[$name]); + } }