作者 lyh

变更数据

... ... @@ -29,9 +29,6 @@ class GeoQuestionRes extends Command
* @var string
*/
protected $signature = 'geo_question_result';
public $porject_id;//记录当时执行的project_id
/**
* The console command description.
*
... ... @@ -40,6 +37,14 @@ class GeoQuestionRes extends Command
protected $description = 'geo设置请求获取结果';
public function demo()
{
// 1 2
// getTaskId -> redis -> [] 1、unlock -> select ; 2:lock sleep
// 1:select, 2:redis -> pop task
// last:mysql status:0, 1:running 2:1->running
}
/**
* @return bool
*/
... ... @@ -51,6 +56,8 @@ class GeoQuestionRes extends Command
sleep(300);
continue;
}
$key = 'geo_question_result_' . date('Y-m-d') . '_' . $task_id;
$ttl = 600;
$this->output('执行的任务ID:' . $task_id);
$geoQuestionModel = new GeoQuestion();
$taskInfo = $geoQuestionModel->read(['id'=>$task_id]);
... ... @@ -80,6 +87,7 @@ class GeoQuestionRes extends Command
$geoResultModel = new GeoQuestionResult();
$geoLogModel = new GeoQuestionLog();
foreach ($taskInfo['question'] as $question) {
$en_question = Translate::tran($question, 'zh') ?? '';
$this->output('项目ID:' . $taskInfo['project_id'] . ', 问题 开始:' . $question);
foreach ($platformsArr as $platform) {
... ... @@ -339,16 +347,15 @@ class GeoQuestionRes extends Command
$key = 'geo_task_list';
$task_id = Redis::rpop($key);
if(empty($task_id)){
//todo::这里需要执行统计一次,统计当前项目当前日期的统计
# TODO 按照项目进行获取, 一个项目当天需要将所有跑完
$project_id = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->orderBy('next_time', 'asc')->value('project_id');
if (!empty($project_id)){
$this->project_id = $project_id;
$ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');
foreach ($ids as $id) {
Redis::lpush($key, $id);
$project_ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->orderBy('next_time', 'asc')->distinct()->pluck('project_id');
if(!empty($project_ids)){
foreach ($project_ids as $project_id){
$ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');
foreach ($ids as $id) {
Redis::lpush($key, $id);
}
$task_id = Redis::rpop($key);
}
$task_id = Redis::rpop($key);
}
}
return $task_id;
... ...