Skip to content

Commit

Permalink
fix:异步任务序列化失败
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkioTomas committed May 28, 2023
1 parent 2a38105 commit 515f16d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function isDarkMode() {


if(!TaskerManager::has("App心跳守护进程")){
TaskerManager::add(TaskerTime::hour(0),new DaemonTasker(),"App心跳守护进程",-1);
TaskerManager::add(TaskerTime::nMinute(1),new DaemonTasker(),"App心跳守护进程",-1);
}


Expand Down
4 changes: 4 additions & 0 deletions src/app/task/DaemonTasker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

namespace app\task;

use app\controller\api\App;
use cleanphp\base\Config;
use cleanphp\cache\Cache;
use cleanphp\file\Log;
use library\mail\AnkioMail;
use library\task\TaskerAbstract;
use Throwable;
Expand All @@ -35,6 +37,7 @@ public function getTimeOut(): int
*/
public function onStart()
{

$last = Cache::init()->get("last_heart");
$online = false;
if (time() - $last <= 60 * 15) {
Expand All @@ -44,6 +47,7 @@ public function onStart()
$file = AnkioMail::compileNotify("#e74c3c", "#fff", Config::getConfig("login")['image'],"Vpay", "App客户端心跳掉线", "<p>App客户端心跳掉线,请检查手机端监控</p><p>最后心跳时间:" . date("Y-m-d H:i:s", $last) . "</p>");
AnkioMail::send(Config::getConfig("mail")['received'], "App客户端心跳掉线", $file, "Vpay");
}
\cleanphp\App::$debug && Log::record("Daemon","App心跳检测完成");

}

Expand Down
6 changes: 3 additions & 3 deletions src/app/view/error/error.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
/>
<!-- MDB ESSENTIAL -->
{if $theme == "dark"}
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.dark.min.css?v={$__version}"/>
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.dark.min.css"/>
{else}
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.min.css?v={$__version}"/>
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.min.css"/>
{/if}
<!-- MDB PLUGINS -->
{* <link rel="stylesheet" href="../../public/plugins/css/all.min.css" />*}
<!-- Custom styles -->
<script src="../../public/js/theme.js?v={$__version}"></script>
<script src="../../public/js/theme.js"></script>
</head>

<body>
Expand Down
4 changes: 3 additions & 1 deletion src/cleanphp/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use cleanphp\base\Dump;
use cleanphp\base\Route;
use cleanphp\closure\SerializableClosure;
use cleanphp\file\Log;
use cleanphp\process\Async;
use cleanphp\process\AsyncObject;

Expand Down Expand Up @@ -230,7 +231,8 @@ function __unserialize(string $data, array $options = null)
SerializableClosure::unwrapClosures($data);
SerializableClosure::exitContext();
}catch (\cleanphp\exception\NoticeException $exception){
return $data;
Log::record("__unserialize", "反序列化错误:".$exception->getMessage());
return null;
}
return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/task/TaskInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class TaskInfo
public int $next = 0;//下次的执行时间
public bool $loop = false;//是否循环
public int $times = 0;//循环次数
public ?TaskerAbstract $closure = null;//序列化的执行事件
public ?string $closure = null;//序列化的执行事件
}
5 changes: 3 additions & 2 deletions src/library/task/TaskerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static function add(string $cron, TaskerAbstract $taskerAbstract, string
$task->key = uniqid("task_");

$task->next = CronExpression::factory($cron)->getNextRunDate()->getTimestamp();
$task->closure = $taskerAbstract;
$task->closure = __serialize($taskerAbstract);
$list = self::getList();
$list[] = $task;
Cache::init(0, Variables::getCachePath("tasker", DS))->set("tasker_list", $list);
Expand All @@ -176,6 +176,7 @@ public static function run()
{

$data = self::getList();
App::$debug && Log::record("Tasker", "当前定时任务列表:".print_r($data,true));
/**
* @var $value TaskInfo
*/
Expand All @@ -192,7 +193,7 @@ public static function run()
/**
* @var TaskerAbstract $task
*/
$task = $value->closure;
$task = __unserialize($value->closure);
$timeout = $task->getTimeOut();

go(function () use ($task) {
Expand Down

0 comments on commit 515f16d

Please sign in to comment.