| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class Process implements CustomProcessInterface |
||
| 13 | { |
||
| 14 | /**@var Client $apollo */ |
||
| 15 | protected static $apollo; |
||
| 16 | |||
| 17 | public static function getDefinition() |
||
| 18 | { |
||
| 19 | return [ |
||
| 20 | 'apollo' => [ |
||
| 21 | 'class' => static::class, |
||
| 22 | 'redirect' => false, |
||
| 23 | 'pipe' => 0, |
||
| 24 | 'enable' => (bool)getenv('ENABLE_APOLLO'), |
||
| 25 | ], |
||
| 26 | ]; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function callback(Server $swoole, SwooleProcess $process) |
||
| 30 | { |
||
| 31 | $filename = base_path('.env'); |
||
| 32 | if (isset($_ENV['_ENV'])) { |
||
| 33 | $filename .= '.' . $_ENV['_ENV']; |
||
| 34 | } |
||
| 35 | |||
| 36 | self::$apollo = Client::createFromEnv(); |
||
| 37 | self::$apollo->startWatchNotification(function (array $notifications) use ($process, $filename) { |
||
| 38 | $configs = self::$apollo->pullAllAndSave($filename); |
||
| 39 | app('log')->info('[ApolloProcess] Pull all configurations', $configs); |
||
| 40 | Portal::runLaravelSCommand(base_path(), 'reload'); |
||
| 41 | if (Context::inCoroutine()) { |
||
| 42 | Coroutine::sleep(5); |
||
| 43 | } else { |
||
| 44 | sleep(5); |
||
| 45 | } |
||
| 46 | }); |
||
| 47 | } |
||
| 48 | |||
| 49 | public static function onReload(Server $swoole, SwooleProcess $process) |
||
| 53 | } |
||
| 54 | } |