| Total Complexity | 5 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | class PrometheusCollectorProcess implements CustomProcessInterface |
||
| 12 | { |
||
| 13 | private static $timerId; |
||
| 14 | |||
| 15 | public static function callback(Server $swoole, Process $process) |
||
| 16 | { |
||
| 17 | /**@var \Hhxsv5\LaravelS\Components\Prometheus\PrometheusCollector $collector */ |
||
| 18 | $collector = app(SwooleWorkerCollector::class); |
||
| 19 | $workerNum = $swoole->setting['worker_num']; |
||
| 20 | $taskWorkerNum = isset($swoole->setting['task_worker_num']) ? $swoole->setting['task_worker_num'] : 0; |
||
| 21 | $totalNum = $workerNum + $taskWorkerNum - 1; |
||
| 22 | $workerIds = range(0, $totalNum); |
||
| 23 | $runJob = function () use ($swoole, $workerIds, $collector) { |
||
| 24 | foreach ($workerIds as $workerId) { |
||
| 25 | $swoole->sendMessage($collector, $workerId); |
||
| 26 | } |
||
| 27 | }; |
||
| 28 | |||
| 29 | $interval = config('prometheus.collect_metrics_interval', 10) * 1000; |
||
| 30 | self::$timerId = Timer::tick($interval, $runJob); |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function onReload(Server $swoole, Process $process) |
||
| 34 | { |
||
| 35 | Timer::clear(self::$timerId); |
||
| 36 | } |
||
| 37 | |||
| 38 | public static function onStop(Server $swoole, Process $process) |
||
| 41 | } |
||
| 42 | } |