modify
This commit is contained in:
@@ -44,13 +44,11 @@ class OnPipeMessage extends Callback
|
||||
*/
|
||||
private function onCrontabWorker(array $message): string
|
||||
{
|
||||
if (!isset($message['handler'])) {
|
||||
if (empty($handler = $message['handler'] ?? null)) {
|
||||
throw new Exception('unknown handler');
|
||||
}
|
||||
|
||||
/** @var Crontab $crontab */
|
||||
$crontab = swoole_unserialize($message['handler']);
|
||||
$crontab->increment()->execute();
|
||||
/** @var Crontab $handler */
|
||||
$handler->increment()->execute();
|
||||
return 'success';
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -184,16 +184,14 @@ abstract class Crontab extends BaseObject
|
||||
{
|
||||
$redis = Snowflake::app()->getRedis();
|
||||
if (!$redis->exists('stop:crontab:' . $this->getName())) {
|
||||
$redis->del('crontab:' . $this->getName());
|
||||
$redis->del('stop:crontab:' . $this->getName());
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
$redis->set('crontab:' . ($name = $this->getName()), swoole_serialize($this));
|
||||
|
||||
$tickTime = time() + $this->getTickTime();
|
||||
|
||||
$redis->zAdd(Producer::CRONTAB_KEY, $tickTime, $name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstract public function process(): mixed;
|
||||
@@ -217,21 +215,24 @@ abstract class Crontab extends BaseObject
|
||||
|
||||
/**
|
||||
* @param $application
|
||||
* @throws Exception
|
||||
* @return bool|int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function isRecover($application)
|
||||
public function isRecover($application): bool|int
|
||||
{
|
||||
try {
|
||||
$redis = Snowflake::app()->getRedis();
|
||||
if ($application->isExit()) {
|
||||
return;
|
||||
return $redis->del('crontab:' . $this->getName());
|
||||
}
|
||||
if ($application->isMaxExecute()) {
|
||||
call_user_func([$application, 'max_execute'], ...$application->params);
|
||||
return $redis->del('crontab:' . $this->getName());
|
||||
} else {
|
||||
$application->recover();
|
||||
return $application->recover();
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
logger()->addError($throwable, 'throwable');
|
||||
return logger()->addError($throwable, 'throwable');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ class Producer extends Component
|
||||
}
|
||||
|
||||
$tickTime = time() + $crontab->getTickTime();
|
||||
|
||||
$redis->del('stop:crontab:' . $name, 120);
|
||||
|
||||
$result = $redis->zAdd(self::CRONTAB_KEY, $tickTime, $name);
|
||||
|
||||
@@ -67,8 +67,8 @@ class Zookeeper extends Process
|
||||
{
|
||||
try {
|
||||
$params['action'] = 'crontab';
|
||||
$params['handler'] = $redis->get('crontab:' . $value);
|
||||
$redis->del('crontab:' . $value);
|
||||
$params['handler'] = swoole_unserialize($redis->get('crontab:' . $value));
|
||||
|
||||
$result = $server->sendMessage($params, $workerId = random_int(0, $setting - 1));
|
||||
|
||||
var_dump('send crontab to ' . $workerId . ' ' . intval($result));
|
||||
|
||||
Reference in New Issue
Block a user