This commit is contained in:
as2252258@163.com
2021-04-11 15:38:23 +08:00
parent d4b64c3af2
commit 60fa2cb896
3 changed files with 136 additions and 120 deletions
+46 -45
View File
@@ -19,68 +19,69 @@ 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 Exception
*/
public function onHandler(\Swoole\Process $process): void
{
$crontab = Snowflake::app()->get('crontab');
$crontab->clearAll();
/**
* @param \Swoole\Process $process
* @throws Exception
*/
public function onHandler(\Swoole\Process $process): void
{
$crontab = Snowflake::app()->get('crontab');
$crontab->clearAll();
if (Snowflake::getPlatform()->isLinux()) {
name($this->pid, 'Crontab zookeeper.');
}
Timer::tick(1000, function () {
$startTime = time();
if (Snowflake::getPlatform()->isLinux()) {
name($this->pid, 'Crontab zookeeper.');
}
Timer::tick(1000, function () {
$startTime = time();
$redis = Snowflake::app()->getRedis();
$redis = Snowflake::app()->getRedis();
$redis->multi();
$range = $redis->zRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime);
$redis->zRemRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime);
$redis->multi();
$range = $redis->zRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime);
$redis->zRemRangeByScore(Producer::CRONTAB_KEY, '0', (string)$startTime);
$redis->exec();
$redis->release();
/** @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));
}
});
}
foreach ($range as $value) {
$consumer->write('crontab:' . md5($value));
}
});
}
/**
* @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]);
}
/**
* @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]);
}
}