正在显示
1 个修改的文件
包含
20 行增加
和
11 行删除
| @@ -73,24 +73,33 @@ class SyncSubmitTaskDistribution extends Command | @@ -73,24 +73,33 @@ class SyncSubmitTaskDistribution extends Command | ||
| 73 | try { | 73 | try { |
| 74 | $table = (new SyncSubmitTaskModel())->getTable(); | 74 | $table = (new SyncSubmitTaskModel())->getTable(); |
| 75 | $new_table = $table . '_backup_' . date('Ymd'); | 75 | $new_table = $table . '_backup_' . date('Ymd'); |
| 76 | - | 76 | + if(Schema::hasTable($new_table)){ |
| 77 | + $new_table = $table . '_backup_' . date('YmdH'); | ||
| 78 | + } | ||
| 77 | //重命名当前表 | 79 | //重命名当前表 |
| 78 | Schema::rename($table, $new_table); | 80 | Schema::rename($table, $new_table); |
| 79 | //克隆表数据 | 81 | //克隆表数据 |
| 80 | DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table); | 82 | DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table); |
| 81 | 83 | ||
| 82 | //未入队的写到新表 | 84 | //未入队的写到新表 |
| 83 | - $list = DB::table($new_table)->where('status', 0)->get(); | ||
| 84 | - $data = []; | ||
| 85 | - foreach ($list as $task) { | ||
| 86 | - $data[] = [ | ||
| 87 | - 'type' => $task->type, | ||
| 88 | - 'data' => $task->data, | ||
| 89 | - 'created_at' => $task->created_at, | ||
| 90 | - 'updated_at' => $task->updated_at, | ||
| 91 | - ]; | 85 | + $page = 1; |
| 86 | + while (true){ | ||
| 87 | + $list = DB::table($new_table)->where('status', 0)->forPage($page, 5000)->get(); | ||
| 88 | + if(!count($list)){ | ||
| 89 | + break; | ||
| 90 | + } | ||
| 91 | + $data = []; | ||
| 92 | + foreach ($list as $task) { | ||
| 93 | + $data[] = [ | ||
| 94 | + 'type' => $task->type, | ||
| 95 | + 'data' => $task->data, | ||
| 96 | + 'created_at' => $task->created_at, | ||
| 97 | + 'updated_at' => $task->updated_at, | ||
| 98 | + ]; | ||
| 99 | + } | ||
| 100 | + $data && SyncSubmitTaskModel::insert($data); | ||
| 101 | + $page++; | ||
| 92 | } | 102 | } |
| 93 | - $data && SyncSubmitTaskModel::insert($data); | ||
| 94 | 103 | ||
| 95 | DB::commit(); | 104 | DB::commit(); |
| 96 | 105 |
-
请 注册 或 登录 后发表评论