Completed
Push — master ( d61801...46edea )
by Biao
05:21
created

ApolloServiceProcess::getDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Hhxsv5\LaravelS\Swoole\Process;
4
5
use Hhxsv5\LaravelS\Components\Apollo\Apollo;
6
use Swoole\Coroutine;
7
use Swoole\Http\Server;
8
use Swoole\Process;
9
10
class ApolloServiceProcess implements CustomProcessInterface
11
{
12
    /**@var Apollo $apollo */
13
    protected static $apollo;
14
15
    public static function getDefinition()
16
    {
17
        return [
18
            'apollo-service' => [
19
                'class'    => self::class,
20
                'redirect' => false,
21
                'pipe'     => 0,
22
            ],
23
        ];
24
    }
25
26
    public static function callback(Server $swoole, Process $process)
27
    {
28
        self::$apollo = Apollo::createFromEnv();
29
        self::$apollo->startWatchNotification(function (array $notifications) use ($swoole) {
0 ignored issues
show
Unused Code introduced by
The parameter $notifications is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
        self::$apollo->startWatchNotification(function (/** @scrutinizer ignore-unused */ array $notifications) use ($swoole) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
            self::$apollo->pullAllAndSave(base_path('.env'), false);
31
            $swoole->reload();
32
            Coroutine::sleep(3);
33
        });
34
    }
35
36
    public static function onReload(Server $swoole, Process $process)
37
    {
38
        // Stop the process...
39
        self::$apollo->stopWatchNotification();
40
    }
41
}