This commit is contained in:
as2252258@163.com
2021-02-28 17:20:59 +08:00
parent fae8eb73a1
commit 5797d87068
2 changed files with 14 additions and 1 deletions
+2
View File
@@ -35,6 +35,8 @@ class OnWorkerStart extends Callback
public function onHandler(Server $server, int $worker_id): void public function onHandler(Server $server, int $worker_id): void
{ {
Coroutine::set(['enable_deadlock_check' => false]); Coroutine::set(['enable_deadlock_check' => false]);
Snowflake::app()->stateInit();
if ($worker_id >= $server->setting['worker_num']) { if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id); $this->onTask($server, $worker_id);
} else { } else {
+12 -1
View File
@@ -93,13 +93,21 @@ abstract class BaseApplication extends Service
} }
/**
* @return $this
*/
public function stateInit() public function stateInit()
{ {
$this->taskNumber = 0; $this->taskNumber = 0;
$this->state = 'SWOOLE_WORKER_IDLE'; $this->state = 'SWOOLE_WORKER_IDLE';
return $this;
} }
/**
* @return $this
*/
public function decrement() public function decrement()
{ {
$this->taskNumber -= 1; $this->taskNumber -= 1;
@@ -107,9 +115,13 @@ abstract class BaseApplication extends Service
$this->taskNumber = 0; $this->taskNumber = 0;
$this->state = 'SWOOLE_WORKER_IDLE'; $this->state = 'SWOOLE_WORKER_IDLE';
} }
return $this;
} }
/**
* @return $this
*/
public function increment() public function increment()
{ {
$this->taskNumber += 1; $this->taskNumber += 1;
@@ -119,7 +131,6 @@ abstract class BaseApplication extends Service
} else { } else {
$this->state = 'SWOOLE_WORKER_BUSY'; $this->state = 'SWOOLE_WORKER_BUSY';
} }
return $this; return $this;
} }