1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resta\Worker; |
4
|
|
|
|
5
|
|
|
use Resta\Support\Process; |
|
|
|
|
6
|
|
|
use Resta\Contracts\JobContracts; |
7
|
|
|
use Resta\Contracts\ApplicationContracts; |
8
|
|
|
use Resta\Foundation\ApplicationProvider; |
9
|
|
|
use Resta\Contracts\WorkerManagerContracts; |
10
|
|
|
|
11
|
|
|
class SupervisorJob extends ApplicationProvider implements JobContracts |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var null|object |
15
|
|
|
*/ |
16
|
|
|
protected $worker; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Process |
20
|
|
|
*/ |
21
|
|
|
protected $process; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DefaultJob constructor. |
25
|
|
|
* |
26
|
|
|
* @param ApplicationContracts $app |
27
|
|
|
* @param WorkerManagerContracts $worker |
28
|
|
|
*/ |
29
|
|
|
public function __construct(ApplicationContracts $app,WorkerManagerContracts $worker) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($app); |
32
|
|
|
|
33
|
|
|
$this->worker = $worker; |
34
|
|
|
|
35
|
|
|
$this->process = new Process(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* execute job |
40
|
|
|
* |
41
|
|
|
* @return mixed|void |
42
|
|
|
*/ |
43
|
|
|
public function execute() |
44
|
|
|
{ |
45
|
|
|
$this->isSupervisorRunning(); |
46
|
|
|
|
47
|
|
|
if($this->app->get('WORKER_STATUS')===true){ |
48
|
|
|
|
49
|
|
|
$this->stopWorkerForSupervisor(); |
50
|
|
|
} |
51
|
|
|
else{ |
52
|
|
|
|
53
|
|
|
$this->putConfigurationFile(); |
54
|
|
|
|
55
|
|
|
$this->reReadForSupervisor(); |
56
|
|
|
|
57
|
|
|
$this->updateForSupervisor(); |
58
|
|
|
|
59
|
|
|
$this->startWorkerForSupervisor(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
echo $this->getWorkersForSupervisor(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* get workers for supervisor |
67
|
|
|
* |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
|
|
public function getWorkersForSupervisor() |
71
|
|
|
{ |
72
|
|
|
return $this->process->command(config('supervisor.commands.workers')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* check if the supervisor is or not running |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function isSupervisorRunning() |
81
|
|
|
{ |
82
|
|
|
return $this->process->command(config('supervisor.commands.status')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* reread for supervisor |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
public function reReadForSupervisor() |
91
|
|
|
{ |
92
|
|
|
return $this->process->command(config('supervisor.commands.reread')); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* start Worker for supervisor |
97
|
|
|
* |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
|
|
public function startWorkerForSupervisor() |
101
|
|
|
{ |
102
|
|
|
return $this->process->command(config('supervisor.commands.start').' '.$this->app->get('WORKER').':*'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* stop worker for supervisor |
107
|
|
|
* |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
|
|
public function stopWorkerForSupervisor() |
111
|
|
|
{ |
112
|
|
|
return $this->process->command(config('supervisor.commands.stop').' '.$this->app->get('WORKER').':*'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* put configutation file for supervisor |
117
|
|
|
* |
118
|
|
|
* @return mixed|void |
119
|
|
|
*/ |
120
|
|
|
public function putConfigurationFile() |
121
|
|
|
{ |
122
|
|
|
$path = config('supervisor.path').'/'.$this->app->get('WORKER').'.conf'; |
123
|
|
|
|
124
|
|
|
if(files()->exists($path)===false){ |
125
|
|
|
files()->put($path,' |
126
|
|
|
[program:'.$this->app()->get('WORKER').'] |
127
|
|
|
process_name=%(program_name)s_%(process_num)02d |
128
|
|
|
command=php '.root.'/api worker run '.$this->app->get('PROJECT_NAME').' worker:'.$this->worker->getWorker().' |
|
|
|
|
129
|
|
|
autostart=true |
130
|
|
|
autorestart=true |
131
|
|
|
user=root |
132
|
|
|
numprocs=1 |
133
|
|
|
redirect_stderr=true |
134
|
|
|
stdout_logfile='.root.'/worker.log |
135
|
|
|
'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* update for supervisor |
142
|
|
|
* |
143
|
|
|
* @return mixed |
144
|
|
|
*/ |
145
|
|
|
public function updateForSupervisor() |
146
|
|
|
{ |
147
|
|
|
return $this->process->command(config('supervisor.commands.update')); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths