This commit is contained in:
as2252258@163.com
2021-03-20 03:15:58 +08:00
parent 441ac7f3a9
commit 30c460c618
+25 -10
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,18 +37,29 @@ 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) {
try { $this->channel->push($process->read());
$content = $process->read(); }
$_content = json_decode($content, true); }
if (is_null($_content)) {
$this->jobDelivery($content);
} else { private function readByCha()
$this->otherAction($_content); {
} try {
} catch (\Throwable $exception) { $content = $this->channel->pop(-1);
$this->application->error($exception->getMessage());
$_content = json_decode($content, true);
if (is_null($_content)) {
$this->jobDelivery($content);
} else {
$this->otherAction($_content);
} }
} catch (\Throwable $exception) {
$this->application->error($exception->getMessage());
} }
} }