作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !3055
@@ -51,6 +51,12 @@ class GeoQuestionRes extends Command @@ -51,6 +51,12 @@ class GeoQuestionRes extends Command
51 sleep(300); 51 sleep(300);
52 continue; 52 continue;
53 } 53 }
  54 + $lock_key = "geo_task_lock:$task_id";
  55 + if (!Redis::setnx($lock_key, 1)) {
  56 + $this->output("任务 $task_id 已被其他进程锁定,跳过");
  57 + continue;
  58 + }
  59 + Redis::expire($lock_key, 1200); // 1小时自动解锁
54 $this->output('执行的任务ID:' . $task_id); 60 $this->output('执行的任务ID:' . $task_id);
55 $geoQuestionModel = new GeoQuestion(); 61 $geoQuestionModel = new GeoQuestion();
56 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]); 62 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]);
@@ -345,7 +351,10 @@ class GeoQuestionRes extends Command @@ -345,7 +351,10 @@ class GeoQuestionRes extends Command
345 foreach ($project_ids as $project_id){ 351 foreach ($project_ids as $project_id){
346 $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id'); 352 $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');
347 foreach ($ids as $id) { 353 foreach ($ids as $id) {
348 - Redis::lpush($key, $id); 354 + //检查任务是否执行过
  355 + if (!Redis::exists("geo_task_lock:$id")) {
  356 + Redis::lpush($key, $id);
  357 + }
349 } 358 }
350 $task_id = Redis::rpop($key); 359 $task_id = Redis::rpop($key);
351 } 360 }