Skip to content

Commit

Permalink
feat:optimize worker daemon code
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcool committed Jun 1, 2024
1 parent 6345b96 commit f477805
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Worker/AbstractBaseWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,11 @@ public function getStartTime()
/**
* reboot
*
* @param float $wait_time
* @param float $afterWaitTime
* @param bool $includeDynamicProcess
* @return bool
*/
public function reboot(float $waitTime = 10, bool $includeDynamicProcess = true)
public function reboot(float $afterWaitTime = 10, bool $includeDynamicProcess = true)
{
if(!$includeDynamicProcess) {
if (!$this->isStaticProcess()) {
Expand All @@ -1218,24 +1218,24 @@ public function reboot(float $waitTime = 10, bool $includeDynamicProcess = true)
return false;
}

if ($waitTime < 0) {
$waitTime = $this->getWaitTime();
if ($afterWaitTime < 0) {
$afterWaitTime = $this->getWaitTime();
}

if ($waitTime <= 5) {
$waitTime = 5;
if ($afterWaitTime <= 5) {
$afterWaitTime = 5;
}

$pid = $this->getPid();
if (Process::kill($pid, 0)) {
// 优先通知master进程先拉起子进程
$this->notifyMasterRebootNewProcess($this->getProcessName());
$this->isReboot = true;
$this->readyRebootTime = time() + $waitTime;
$this->readyRebootTime = time() + $afterWaitTime;

$channel = new Channel(1);
$timerId = \Swoole\Timer::after($waitTime * 1000, function () use ($pid) {
$this->exitNow($pid, 5);
$timerId = \Swoole\Timer::after($afterWaitTime * 1000, function () use ($pid) {
$this->exitNow($pid, 15);
});

$this->rebootTimerId = $timerId;
Expand Down Expand Up @@ -1370,7 +1370,7 @@ protected function registerTickReboot()
$lifeTime,
function () use ($randSleep, $isWorkerId0) {
if(!$isWorkerId0) {
$this->reboot($this->waitTime + $randSleep);
$this->reboot($randSleep);
}
$this->reboot($this->waitTime);
});
Expand Down

0 comments on commit f477805

Please sign in to comment.