作者 刘锟

import_task

... ... @@ -10,6 +10,7 @@ use App\Models\Mail\Mail;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* Class GoogleRank
... ... @@ -43,7 +44,13 @@ class ProjectImport extends Command
protected function start_import()
{
$task = ImportTask::where('status', ImportTask::STATUS_UN)->first();
$task_id = $this->get_task();
if (!$task_id) {
sleep(2);
return true;
}
$task = ImportTask::where('id', $task_id)->where('status', ImportTask::STATUS_UN)->first();
if (!$task) {
sleep(2);
return true;
... ... @@ -51,6 +58,9 @@ class ProjectImport extends Command
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import start' . PHP_EOL;
$task->status = ImportTask::STATUS_ING;//导入中
$task->save();
$is_gbk = 0;
$file_code_type = $this->get_code_type($task->file_url);
if ($file_code_type === false) {
... ... @@ -86,8 +96,6 @@ class ProjectImport extends Command
$success_count = 0; //成功导入条数
$repeat_count = 0; //过滤已存在条数
if (count($line_of_text) > 1) {
$task->status = ImportTask::STATUS_ING;//导入中
$task->save();
//设置数据库
$project = ProjectServer::useProject($task->project_id);
... ... @@ -144,6 +152,28 @@ class ProjectImport extends Command
sleep(2);
}
//获取任务
protected function get_task()
{
$key = 'console_import_task';
$task_id = Redis::rpop($key);
if ($task_id) {
return $task_id;
}
$task_list = ImportTask::where('status', ImportTask::STATUS_UN)->limit(20)->get();
if ($task_list->count() == 0) {
return false;
}
foreach ($task_list as $value) {
Redis::lpush($key, $value->id);
}
$task_id = Redis::rpop($key);
return $task_id;
}
//判断编码格式
protected function get_code_type($file)
{
... ... @@ -158,7 +188,7 @@ class ProjectImport extends Command
return false;
}
//发站内通知
//发站内通知
protected function send_mail($user_list, $time, $type, $success_count, $repeat_count, $reason)
{
if ($type == ImportTask::TYPE_NEWS) {
... ...