作者 赵彬吉

fix sync_submit_task_distribution

@@ -73,14 +73,21 @@ class SyncSubmitTaskDistribution extends Command @@ -73,14 +73,21 @@ 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(); 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 + }
84 $data = []; 91 $data = [];
85 foreach ($list as $task) { 92 foreach ($list as $task) {
86 $data[] = [ 93 $data[] = [
@@ -91,6 +98,8 @@ class SyncSubmitTaskDistribution extends Command @@ -91,6 +98,8 @@ class SyncSubmitTaskDistribution extends Command
91 ]; 98 ];
92 } 99 }
93 $data && SyncSubmitTaskModel::insert($data); 100 $data && SyncSubmitTaskModel::insert($data);
  101 + $page++;
  102 + }
94 103
95 DB::commit(); 104 DB::commit();
96 105