modify
This commit is contained in:
@@ -26,6 +26,7 @@ class CrontabProcess extends Process
|
|||||||
|
|
||||||
|
|
||||||
private Channel $channel;
|
private Channel $channel;
|
||||||
|
private Coroutine\WaitGroup $waitGroup;
|
||||||
|
|
||||||
|
|
||||||
/** @var Crontab[] $names */
|
/** @var Crontab[] $names */
|
||||||
@@ -38,9 +39,14 @@ class CrontabProcess extends Process
|
|||||||
public function onHandler(\Swoole\Process $process): void
|
public function onHandler(\Swoole\Process $process): void
|
||||||
{
|
{
|
||||||
$this->channel = new Channel(1000);
|
$this->channel = new Channel(1000);
|
||||||
|
|
||||||
|
$this->waitGroup = new Coroutine\WaitGroup();
|
||||||
Coroutine::create(function () {
|
Coroutine::create(function () {
|
||||||
|
$this->waitGroup->add(1);
|
||||||
$this->readByCha();
|
$this->readByCha();
|
||||||
});
|
});
|
||||||
|
$this->waitGroup->wait(-1);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$this->channel->push($process->read());
|
$this->channel->push($process->read());
|
||||||
}
|
}
|
||||||
@@ -54,7 +60,6 @@ class CrontabProcess extends Process
|
|||||||
|
|
||||||
$_content = json_decode($content, true);
|
$_content = json_decode($content, true);
|
||||||
if (is_null($_content)) {
|
if (is_null($_content)) {
|
||||||
var_dump($content);
|
|
||||||
$this->jobDelivery($content);
|
$this->jobDelivery($content);
|
||||||
} else {
|
} else {
|
||||||
$this->otherAction($_content);
|
$this->otherAction($_content);
|
||||||
@@ -113,7 +118,11 @@ class CrontabProcess extends Process
|
|||||||
};
|
};
|
||||||
// $timer = $content->getTickTime() * 10;
|
// $timer = $content->getTickTime() * 10;
|
||||||
|
|
||||||
|
$this->waitGroup->add(1);
|
||||||
|
|
||||||
Timer::after(10000, function () use ($content) {
|
Timer::after(10000, function () use ($content) {
|
||||||
|
$this->waitGroup->add(-1);
|
||||||
|
|
||||||
$this->application->warning('execute crontab ' . date('Y-m-d H:i:s'));
|
$this->application->warning('execute crontab ' . date('Y-m-d H:i:s'));
|
||||||
$content->execute($this);
|
$content->execute($this);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user