From 1106edcb7f23db8f37c55e6ece84894c4899aeab Mon Sep 17 00:00:00 2001 From: lingling Date: Fri, 7 Mar 2025 18:14:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=20Task=20=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E5=92=8C?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E6=94=B6=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- process/Task.php | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/process/Task.php b/process/Task.php index 689ac0e..c1858b5 100644 --- a/process/Task.php +++ b/process/Task.php @@ -7,6 +7,7 @@ use app\model\UserPhone; use app\dao\UserRewardDao; use Workerman\Crontab\Crontab; use app\model\GetLodeLog; +use support\Log; /** * 查询用户是否在线类 @@ -15,46 +16,21 @@ class Task { public function onWorkerStart() { - - // // 每秒钟执行一次 - // new Crontab('*/1 * * * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); - - // // 每5秒执行一次 - // new Crontab('*/5 * * * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); - - // // 每分钟执行一次 - // new Crontab('0 */1 * * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); - - // // 每5分钟执行一次 - // new Crontab('0 */5 * * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); - - // // 每分钟的第一秒执行 - // new Crontab('1 * * * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); - - // // 每天的7点50执行,注意这里省略了秒位 - // new Crontab('50 7 * * *', function(){ - // echo date('Y-m-d H:i:s')."\n"; - // }); // 每1秒执行一次 收取验证码 new Crontab('*/1 * * * * *', function () { $GetLodeLog = GetLodeLog::where('status', 0)->get(); foreach ($GetLodeLog as $key => $value) { - $res = SendCode::get_code($value->phone); - // var_dump($res); - if ($res['status'] == 1 && $res['scanCode'] != null) { - $value->status = 1; - $value->code = $res['scanCode']; - $value->save(); + try { + $res = SendCode::get_code($value->phone); + // var_dump($res); + if ($res['status'] == 1 && $res['scanCode'] != null) { + $value->status = 1; + $value->code = $res['scanCode']; + $value->save(); + } + } catch (\Exception $e) { + // 记录错误日志,避免任务中断 + Log::error("Error processing phone {$value->phone}: " . $e->getMessage()); } } });