e
This commit is contained in:
+14
-7
@@ -22,25 +22,32 @@ class Command extends \Console\Command
|
||||
public $description = 'server start|stop|reload|restart';
|
||||
|
||||
|
||||
const ACTIONS = ['start', 'stop', 'restart'];
|
||||
|
||||
|
||||
/**
|
||||
* @param Input $dtl
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function onHandler(Input $dtl)
|
||||
{
|
||||
$manager = Snowflake::app()->server;
|
||||
$manager->setDaemon($dtl->get('daemon', 0));
|
||||
if ($manager->isRunner()) {
|
||||
$manager->shutdown();
|
||||
|
||||
if (!in_array($dtl->get('action'), self::ACTIONS)) {
|
||||
return $this->error('I don\'t know what I want to do.');
|
||||
}
|
||||
|
||||
if ($manager->isRunner() && $dtl->get('action') == 'start') {
|
||||
return $this->error('Service is running. Please use restart.');
|
||||
}
|
||||
|
||||
$manager->shutdown();
|
||||
if ($dtl->get('action') == 'stop') {
|
||||
return;
|
||||
}
|
||||
if (!in_array($dtl->get('action'), ['start', 'restart'])) {
|
||||
return $this->error('I don\'t know what I want to do.');
|
||||
}
|
||||
$manager->start();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class OnWorkerStart extends Callback
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onHandler(Server $server, $worker_id)
|
||||
public function onHandler(Server $server, int $worker_id)
|
||||
{
|
||||
Snowflake::setWorkerId($server->worker_pid);
|
||||
|
||||
@@ -42,15 +42,14 @@ class OnWorkerStart extends Callback
|
||||
if ($worker_id >= $server->setting['worker_num']) {
|
||||
return;
|
||||
}
|
||||
$this->setWorkerAction($server, $worker_id);
|
||||
$this->setWorkerAction($worker_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $worker_id
|
||||
* @param $socket
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setWorkerAction($socket, $worker_id)
|
||||
private function setWorkerAction($worker_id)
|
||||
{
|
||||
try {
|
||||
$this->debug(sprintf('Worker #%d is start.....', $worker_id));
|
||||
@@ -58,7 +57,7 @@ class OnWorkerStart extends Callback
|
||||
if (!$event->exists(Event::SERVER_WORKER_START)) {
|
||||
return;
|
||||
}
|
||||
$event->trigger(Event::SERVER_WORKER_START);
|
||||
$event->trigger(Event::SERVER_WORKER_START, [$worker_id]);
|
||||
} catch (\Throwable $exception) {
|
||||
Snowflake::app()->getLogger()->write($exception->getMessage(), 'worker');
|
||||
}
|
||||
|
||||
@@ -48,10 +48,6 @@ class Queue extends \Snowflake\Process\Process
|
||||
$this->waiting = Snowflake::createObject(Waiting::class);
|
||||
$this->running = Snowflake::createObject(Running::class);
|
||||
$this->complete = Snowflake::createObject(Complete::class);
|
||||
|
||||
Process::signal(9 | 15, function () {
|
||||
$this->shutdown = true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,5 +38,4 @@ abstract class Process extends \Swoole\Process
|
||||
Snowflake::setWorkerId($this->pid);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user