This commit is contained in:
2021-03-24 17:57:08 +08:00
parent 2610267aba
commit 6df0cb4003
11 changed files with 576 additions and 532 deletions
+10 -6
View File
@@ -101,12 +101,11 @@ class OnTask extends Callback
*/
private function runTaskHandler($data): ?array
{
Coroutine\defer(function () {
fire(Event::SYSTEM_RESOURCE_RELEASES);
logger()->insert();
});
try {
$serialize = $this->before($data);
if ($serialize === null) {
throw new Exception('unpack error.');
}
$params = $serialize->getParams();
if (is_object($params)) {
$params = get_object_vars($params);
@@ -115,12 +114,17 @@ class OnTask extends Callback
$finish['params'] = $params;
$finish['status'] = 'success';
$finish['info'] = $serialize->onHandler();
return $finish;
} catch (\Throwable $exception) {
$finish['status'] = 'error';
$finish['info'] = $this->format($exception);
$this->error($exception, 'Task');
return $finish;
} finally {
fire(Event::SYSTEM_RESOURCE_RELEASES);
logger()->insert();
}
return $finish;
}
@@ -130,7 +134,7 @@ class OnTask extends Callback
*/
protected function before($data): ?Task
{
if (empty($serialize = unserialize($data))) {
if (empty($serialize = swoole_unserialize($data))) {
return null;
}
if (!($serialize instanceof ITask)) {
+1 -1
View File
@@ -105,7 +105,7 @@ class Producer extends Component
}
$groupId = $consumers['groupId'];
}
$this->setGroupId($groupId)->setTopic($topic)->delivery(Json::encode($params));
$this->setGroupId($groupId)->setTopic($topic)->delivery(swoole_serialize($params));
}
+2
View File
@@ -24,6 +24,8 @@ class Struct
*/
public function __construct($topic, Message $message)
{
$message->payload = swoole_unserialize($message->payload);
$this->topic = $topic;
$this->offset = $message->offset;
$this->part = $message->partition;
+1 -1
View File
@@ -31,7 +31,7 @@ class Crontab extends Component
$name = md5($crontab->getName());
$redis->set('crontab:' . $name, serialize($crontab));
$redis->set('crontab:' . $name, swoole_serialize($crontab));
$tickTime = time() + $crontab->getTickTime();
+1 -1
View File
@@ -52,7 +52,7 @@ class Async extends Component
$randWorkerId = random_int(0, $server->setting['task_worker_num'] - 1);
$server->task(serialize($class), $randWorkerId);
$server->task(swoole_serialize($class), $randWorkerId);
}
}
+2 -2
View File
@@ -32,7 +32,7 @@ class File extends Component implements ICache
public function set($key, $val): string|int
{
if (is_array($val) || is_object($val)) {
$val = serialize($val);
$val = swoole_serialize($val);
}
$tmpFile = $this->getCacheKey($key);
if (!$this->exists($tmpFile)) {
@@ -128,7 +128,7 @@ class File extends Component implements ICache
return false;
}
$content = file_get_contents($tmpFile);
return unserialize($content);
return swoole_unserialize($content);
}
/**
+1 -1
View File
@@ -105,7 +105,7 @@ class Str
*/
public static function isSerialize($data, $callBack = null): bool
{
$false = !empty($data) && unserialize($data) !== false;
$false = !empty($data) && swoole_unserialize($data) !== false;
if ($false && is_callable($callBack, true)) {
return call_user_func($callBack, $data);
}
+2 -2
View File
@@ -58,7 +58,7 @@ class CrontabProcess extends Process
foreach ($range as $value) {
$crontab = $redis->get('crontab:' . md5($value));
$redis->del('crontab:' . md5($value));
if (empty($crontab) || !($crontab = unserialize($crontab))) {
if (empty($crontab) || !($crontab = swoole_unserialize($crontab))) {
continue;
}
Coroutine::create(function (Crontab $value, int $startTime) {
@@ -114,7 +114,7 @@ class CrontabProcess extends Process
$name = md5($crontab->getName());
$redis->set('crontab:' . $name, serialize($crontab));
$redis->set('crontab:' . $name, swoole_serialize($crontab));
$tickTime = time() + $crontab->getTickTime();
+1 -1
View File
@@ -316,7 +316,7 @@ class Snowflake
$class = static::createObject($class);
$class->setParams($params);
$server->task(serialize($class));
$server->task(swoole_serialize($class));
}
+1 -1
View File
@@ -87,7 +87,7 @@ class TypesOfValidator extends BaseValidator
if (!is_string($value) || is_numeric($value)) {
return $this->addError('The ' . $this->field . ' not is serialize data.');
}
if (false === unserialize($value)) {
if (false === swoole_unserialize($value)) {
return $this->addError('The ' . $this->field . ' not is serialize data.');
}
return true;
+554 -516
View File
File diff suppressed because it is too large Load Diff