1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resta\Worker; |
4
|
|
|
|
5
|
|
|
use Resta\Contracts\JobContracts; |
6
|
|
|
|
7
|
|
|
class SupervisorJob extends JobAbstract implements JobContracts |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* execute job |
11
|
|
|
* |
12
|
|
|
* @return mixed|void |
13
|
|
|
*/ |
14
|
|
|
public function execute() |
15
|
|
|
{ |
16
|
|
|
$this->isSupervisorRunning(); |
17
|
|
|
|
18
|
|
|
$this->{$this->jobProcessor()}(); |
19
|
|
|
|
20
|
|
|
echo $this->getWorkersForSupervisor(); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* start job |
25
|
|
|
* |
26
|
|
|
* @return mixed|void |
27
|
|
|
*/ |
28
|
|
|
public function start() |
29
|
|
|
{ |
30
|
|
|
$this->putConfigurationFile(); |
31
|
|
|
|
32
|
|
|
$this->reReadForSupervisor(); |
33
|
|
|
|
34
|
|
|
$this->updateForSupervisor(); |
35
|
|
|
|
36
|
|
|
$this->startWorkerForSupervisor(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* stop job |
41
|
|
|
* |
42
|
|
|
* @return mixed|void |
43
|
|
|
*/ |
44
|
|
|
public function stop() |
45
|
|
|
{ |
46
|
|
|
$this->stopWorkerForSupervisor(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* get status worker |
51
|
|
|
* |
52
|
|
|
* @return mixed|void |
53
|
|
|
*/ |
54
|
|
|
public function status() |
55
|
|
|
{ |
56
|
|
|
// |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* get workers for supervisor |
61
|
|
|
* |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
public function getWorkersForSupervisor() |
65
|
|
|
{ |
66
|
|
|
return $this->process->command(config('supervisor.commands.workers')); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* check if the supervisor is or not running |
71
|
|
|
* |
72
|
|
|
* @return mixed|void |
73
|
|
|
*/ |
74
|
|
|
public function isSupervisorRunning() |
75
|
|
|
{ |
76
|
|
|
$this->process->command(config('supervisor.commands.status')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* reread for supervisor |
81
|
|
|
* |
82
|
|
|
* @return mixed |
83
|
|
|
*/ |
84
|
|
|
public function reReadForSupervisor() |
85
|
|
|
{ |
86
|
|
|
return $this->process->command(config('supervisor.commands.reread')); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* start Worker for supervisor |
91
|
|
|
* |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
|
|
public function startWorkerForSupervisor() |
95
|
|
|
{ |
96
|
|
|
return $this->process->command(config('supervisor.commands.start').' '.$this->app->get('WORKER').':*'); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* stop worker for supervisor |
101
|
|
|
* |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
public function stopWorkerForSupervisor() |
105
|
|
|
{ |
106
|
|
|
return $this->process->command(config('supervisor.commands.stop').' '.$this->app->get('WORKER').':*'); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* put configutation file for supervisor |
111
|
|
|
* |
112
|
|
|
* @return mixed|void |
113
|
|
|
*/ |
114
|
|
|
public function putConfigurationFile() |
115
|
|
|
{ |
116
|
|
|
$path = config('supervisor.path').'/'.$this->app->get('WORKER').'.conf'; |
117
|
|
|
|
118
|
|
|
if(files()->exists($path)===false){ |
119
|
|
|
files()->put($path,' |
120
|
|
|
[program:'.$this->app()->get('WORKER').'] |
121
|
|
|
process_name=%(program_name)s_%(process_num)02d |
122
|
|
|
command=php '.root.'/api worker start '.$this->app->get('PROJECT_NAME').' worker:'.$this->worker->getWorker().' apply:default |
|
|
|
|
123
|
|
|
autostart=true |
124
|
|
|
autorestart=true |
125
|
|
|
user=root |
126
|
|
|
numprocs=1 |
127
|
|
|
redirect_stderr=true |
128
|
|
|
stdout_logfile='.config('supervisor.log').'/worker.log |
129
|
|
|
'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* update for supervisor |
136
|
|
|
* |
137
|
|
|
* @return mixed |
138
|
|
|
*/ |
139
|
|
|
public function updateForSupervisor() |
140
|
|
|
{ |
141
|
|
|
return $this->process->command(config('supervisor.commands.update')); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.