Skip to content

Commit 515f16d

Browse files
committed
fix:异步任务序列化失败
1 parent 2a38105 commit 515f16d

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/app/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function isDarkMode() {
7373

7474

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

7979

src/app/task/DaemonTasker.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace app\task;
1515

16+
use app\controller\api\App;
1617
use cleanphp\base\Config;
1718
use cleanphp\cache\Cache;
19+
use cleanphp\file\Log;
1820
use library\mail\AnkioMail;
1921
use library\task\TaskerAbstract;
2022
use Throwable;
@@ -35,6 +37,7 @@ public function getTimeOut(): int
3537
*/
3638
public function onStart()
3739
{
40+
3841
$last = Cache::init()->get("last_heart");
3942
$online = false;
4043
if (time() - $last <= 60 * 15) {
@@ -44,6 +47,7 @@ public function onStart()
4447
$file = AnkioMail::compileNotify("#e74c3c", "#fff", Config::getConfig("login")['image'],"Vpay", "App客户端心跳掉线", "<p>App客户端心跳掉线,请检查手机端监控</p><p>最后心跳时间:" . date("Y-m-d H:i:s", $last) . "</p>");
4548
AnkioMail::send(Config::getConfig("mail")['received'], "App客户端心跳掉线", $file, "Vpay");
4649
}
50+
\cleanphp\App::$debug && Log::record("Daemon","App心跳检测完成");
4751

4852
}
4953

src/app/view/error/error.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
/>
1818
<!-- MDB ESSENTIAL -->
1919
{if $theme == "dark"}
20-
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.dark.min.css?v={$__version}"/>
20+
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.dark.min.css"/>
2121
{else}
22-
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.min.css?v={$__version}"/>
22+
<link id="theme-link" rel="stylesheet" href="../../public/css/mdb.min.css"/>
2323
{/if}
2424
<!-- MDB PLUGINS -->
2525
{* <link rel="stylesheet" href="../../public/plugins/css/all.min.css" />*}
2626
<!-- Custom styles -->
27-
<script src="../../public/js/theme.js?v={$__version}"></script>
27+
<script src="../../public/js/theme.js"></script>
2828
</head>
2929

3030
<body>

src/cleanphp/helper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use cleanphp\base\Dump;
1717
use cleanphp\base\Route;
1818
use cleanphp\closure\SerializableClosure;
19+
use cleanphp\file\Log;
1920
use cleanphp\process\Async;
2021
use cleanphp\process\AsyncObject;
2122

@@ -230,7 +231,8 @@ function __unserialize(string $data, array $options = null)
230231
SerializableClosure::unwrapClosures($data);
231232
SerializableClosure::exitContext();
232233
}catch (\cleanphp\exception\NoticeException $exception){
233-
return $data;
234+
Log::record("__unserialize", "反序列化错误:".$exception->getMessage());
235+
return null;
234236
}
235237
return $data;
236238
}

src/library/task/TaskInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class TaskInfo
2222
public int $next = 0;//下次的执行时间
2323
public bool $loop = false;//是否循环
2424
public int $times = 0;//循环次数
25-
public ?TaskerAbstract $closure = null;//序列化的执行事件
25+
public ?string $closure = null;//序列化的执行事件
2626
}

src/library/task/TaskerManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static function add(string $cron, TaskerAbstract $taskerAbstract, string
157157
$task->key = uniqid("task_");
158158

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

178178
$data = self::getList();
179+
App::$debug && Log::record("Tasker", "当前定时任务列表:".print_r($data,true));
179180
/**
180181
* @var $value TaskInfo
181182
*/
@@ -192,7 +193,7 @@ public static function run()
192193
/**
193194
* @var TaskerAbstract $task
194195
*/
195-
$task = $value->closure;
196+
$task = __unserialize($value->closure);
196197
$timeout = $task->getTimeOut();
197198

198199
go(function () use ($task) {

0 commit comments

Comments
 (0)