mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Format code.
This commit is contained in:
parent
765774bd8c
commit
d567fb2f34
@ -31,7 +31,6 @@ use InfluxDB\Driver\DriverInterface;
|
||||
use InfluxDB\Point;
|
||||
use Prometheus\CollectorRegistry;
|
||||
use Prometheus\Sample;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
class MetricFactory implements MetricFactoryInterface
|
||||
{
|
||||
@ -119,7 +118,7 @@ class MetricFactory implements MetricFactoryInterface
|
||||
}
|
||||
while (true) {
|
||||
$workerExited = CoordinatorManager::get(Constants::ON_WORKER_EXIT)->yield($interval);
|
||||
if ($workerExited){
|
||||
if ($workerExited) {
|
||||
break;
|
||||
}
|
||||
$points = [];
|
||||
|
@ -17,6 +17,7 @@ use Hyperf\Metric\Contract\CounterInterface;
|
||||
use Hyperf\Metric\Contract\GaugeInterface;
|
||||
use Hyperf\Metric\Contract\HistogramInterface;
|
||||
use Hyperf\Metric\Contract\MetricFactoryInterface;
|
||||
use Hyperf\Utils\Coordinator\Constants;
|
||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||
|
||||
class MetricFactory implements MetricFactoryInterface
|
||||
@ -48,7 +49,7 @@ class MetricFactory implements MetricFactoryInterface
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$coordinator = CoordinatorManager::get('workerExit');
|
||||
$coordinator = CoordinatorManager::get(Constants::ON_WORKER_EXIT);
|
||||
$coordinator->yield();
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ use Hyperf\Metric\Contract\HistogramInterface;
|
||||
use Hyperf\Metric\Contract\MetricFactoryInterface;
|
||||
use Hyperf\Metric\Exception\InvalidArgumentException;
|
||||
use Hyperf\Metric\Exception\RuntimeException;
|
||||
use Hyperf\Utils\Coordinator\Constants as Coord;
|
||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||
use Hyperf\Utils\Str;
|
||||
use Prometheus\CollectorRegistry;
|
||||
use Prometheus\RenderTextFormat;
|
||||
use Hyperf\Utils\Coordinator\Constants as Coord;
|
||||
use Swoole\Coroutine\Http\Server;
|
||||
|
||||
class MetricFactory implements MetricFactoryInterface
|
||||
@ -131,7 +131,7 @@ class MetricFactory implements MetricFactoryInterface
|
||||
$port = $this->config->get("metric.metric.{$this->name}.push_port");
|
||||
$this->doRequest("{$host}:{$port}", $this->getNamespace(), 'put');
|
||||
$workerExited = CoordinatorManager::get(Coord::ON_WORKER_EXIT)->yield($interval);
|
||||
if ($workerExited){
|
||||
if ($workerExited) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ use Hyperf\Metric\Contract\HistogramInterface;
|
||||
use Hyperf\Metric\Contract\MetricFactoryInterface;
|
||||
use Hyperf\Utils\Coordinator\Constants;
|
||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
class MetricFactory implements MetricFactoryInterface
|
||||
{
|
||||
@ -91,7 +90,7 @@ class MetricFactory implements MetricFactoryInterface
|
||||
$this->client->startBatch();
|
||||
$workerExited = CoordinatorManager::get(Constants::ON_WORKER_EXIT)->yield($interval);
|
||||
$this->client->endBatch();
|
||||
if ($workerExited){
|
||||
if ($workerExited) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
@ -15,7 +15,6 @@ namespace Hyperf\Metric\Listener;
|
||||
use Hyperf\AsyncQueue\Driver\DriverFactory;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Event\Contract\ListenerInterface;
|
||||
use Hyperf\Framework\Bootstrap\WorkerExitCallback;
|
||||
use Hyperf\Metric\Event\MetricFactoryReady;
|
||||
use Hyperf\Utils\Coordinator\Constants;
|
||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||
@ -82,9 +81,9 @@ class QueueWatcher implements ListenerInterface
|
||||
$failed->set((float) $info['failed']);
|
||||
$timeout->set((float) $info['timeout']);
|
||||
});
|
||||
Coroutine::create(function() use ($timerId) {
|
||||
CoordinatorManager::get(Constants::ON_WORKER_EXIT)->yield();
|
||||
Timer::clear($timerId);
|
||||
Coroutine::create(function () use ($timerId) {
|
||||
CoordinatorManager::get(Constants::ON_WORKER_EXIT)->yield();
|
||||
Timer::clear($timerId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Utils\Coordinator;
|
||||
|
||||
|
||||
class Constants
|
||||
{
|
||||
/**
|
||||
* Swoole onWorkerStart event.
|
||||
*/
|
||||
const ON_WORKER_START = 'workerStart';
|
||||
|
||||
/**
|
||||
* Swoole onWorkerExit event.
|
||||
*/
|
||||
const ON_WORKER_EXIT = 'workerExit';
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ class Coordinator
|
||||
* Yield the current coroutine for a given timeout,
|
||||
* unless the coordinator is woke up from outside.
|
||||
*
|
||||
* @param int|float $timeout
|
||||
* @param float|int $timeout
|
||||
* @return bool returns true if the coordinator has been woken up
|
||||
*/
|
||||
public function yield($timeout = -1): bool
|
||||
{
|
||||
$this->channel->pop((float) $timeout);
|
||||
return $this->channel->errCode === -2;
|
||||
return $this->channel->errCode === SWOOLE_CHANNEL_CLOSED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user