This commit is contained in:
as2252258@163.com
2021-03-20 03:15:58 +08:00
parent 441ac7f3a9
commit 30c460c618
+17 -2
View File
@@ -24,6 +24,10 @@ use Swoole\Timer;
class CrontabProcess extends Process class CrontabProcess extends Process
{ {
private Channel $channel;
/** @var Crontab[] $names */ /** @var Crontab[] $names */
public array $names = []; public array $names = [];
@@ -33,9 +37,21 @@ class CrontabProcess extends Process
*/ */
public function onHandler(\Swoole\Process $process): void public function onHandler(\Swoole\Process $process): void
{ {
$this->channel = new Channel(1000);
Coroutine::create(function () {
$this->readByCha();
});
while (true) { while (true) {
$this->channel->push($process->read());
}
}
private function readByCha()
{
try { try {
$content = $process->read(); $content = $this->channel->pop(-1);
$_content = json_decode($content, true); $_content = json_decode($content, true);
if (is_null($_content)) { if (is_null($_content)) {
$this->jobDelivery($content); $this->jobDelivery($content);
@@ -46,7 +62,6 @@ class CrontabProcess extends Process
$this->application->error($exception->getMessage()); $this->application->error($exception->getMessage());
} }
} }
}
/** /**