This commit is contained in:
2021-02-26 19:53:28 +08:00
parent cd3ed6937c
commit 6e3ecce453
4 changed files with 46 additions and 7 deletions
+37
View File
@@ -50,6 +50,12 @@ abstract class BaseApplication extends Service
use TraitApplication;
private string $state = '';
private int $taskNumber = 0;
/**
* @var string
*/
@@ -78,6 +84,37 @@ abstract class BaseApplication extends Service
}
/**
* @return bool
*/
public function isRun(): bool
{
return $this->state == 'SWOOLE_WORKER_BUSY';
}
public function decrement()
{
$this->taskNumber -= 1;
if ($this->taskNumber <= 0) {
$this->taskNumber = 0;
$this->state = 'SWOOLE_WORKER_IDLE';
}
}
public function increment()
{
$this->taskNumber += 1;
if ($this->taskNumber <= 0) {
$this->taskNumber = 0;
$this->state = 'SWOOLE_WORKER_IDLE';
} else {
$this->state = 'SWOOLE_WORKER_BUSY';
}
}
/**
* @return array
*/