Browse Source

同步增加表,失败重试

visuddhinanda 4 years ago
parent
commit
e9754203fa

+ 7 - 0
app/sync/sync.js

@@ -25,6 +25,7 @@ function sync_push() {
 function sync_stop() {
 	isStop = true;
 }
+var retryCount = 0;
 function sync_do_db(src, dest, time = 1) {
 	let size = 500;
 	while (sync_db_list[sync_curr_do_db].enable == false) {
@@ -86,6 +87,12 @@ function sync_do_db(src, dest, time = 1) {
 				if (isStop) {
 					return;
 				}
+				if (result.error > 0 && retryCount < 2) {
+					retryCount++;
+					sync_do_db(src, dest, time);
+					return;
+				}
+				retryCount = 0;
 				sync_db_list[sync_curr_do_db].finished += parseInt(result.src_row);
 				if (result.src_row >= size) {
 					//没弄完,接着弄

+ 3 - 3
app/sync/sync.php

@@ -77,7 +77,7 @@ $response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false
 $strLocalData = (string)$response->getBody();
 $localData = json_decode($strLocalData,true);
 if($localData["error"]>0){
-	$message .= $localData["message"];
+	$message .="client 拉 id 列表 error:". $localData["message"];
 	$output["message"]=$message;
 	echo json_encode($output, JSON_UNESCAPED_UNICODE);
 	exit;
@@ -135,7 +135,7 @@ else{
 
 	$message .= "<div>";
 	if(count($insert_to_local)>0){
-		$message .=  "需要新增到本地".count($insert_to_local)."条记录 | ";
+		$message .=  "需要新增到目标机".count($insert_to_local)."条记录 | ";
 		
 		#提取数据
 		$idInServer = json_encode($insert_to_local, JSON_UNESCAPED_UNICODE);
@@ -159,7 +159,7 @@ else{
 
 	$message .= "<div>";
 	if(count($update_to_local)>0){
-		$message .=  "需要更新到本地".count($update_to_local)."条记录 | ";
+		$message .=  "需要更新到目标机".count($update_to_local)."条记录 | ";
 		/*
 		$idInServer = json_encode($update_to_local, JSON_UNESCAPED_UNICODE);
 		$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'get','id'=>"{$idInServer}","key"=>$sync_key,"userid"=>$_COOKIE["userid"]]]);

+ 1 - 0
app/sync/table_article.php

@@ -9,6 +9,7 @@ $input = (object) [
     "table" =>  "article",
     "uuid" =>  "id",
     "sync_id" =>  ["id"],
+	"where"=>"",
     "modify_time" =>  "modify_time",
     "receive_time" =>  "receive_time",
     "insert" => [

+ 1 - 0
app/sync/table_article_collect.php

@@ -12,6 +12,7 @@ $input = (object) [
     "table" =>  "collect",
     "uuid" =>  "id",
     "sync_id" =>  ["id"],
+	"where"=>"",
     "modify_time" =>  "modify_time",
     "receive_time" =>  "receive_time",
     "insert" => [

+ 46 - 0
app/sync/table_channel.php

@@ -0,0 +1,46 @@
+<?php
+//header('Content-type: application/json; charset=utf8');
+
+require_once "../path.php";
+require_once "../sync/function.php";
+
+$input = (object) [
+    "database" =>  _FILE_DB_CHANNAL_,
+    "table" =>  "channal",
+    "uuid" =>  "id",
+    "sync_id" =>  ["id"],
+	"where"=>"",
+    "modify_time" =>  "modify_time",
+    "receive_time" =>  "receive_time",
+    "insert" => [
+        'id',
+		'title',
+		'subtitle',
+		'summary',
+		'content',
+		'tag',
+		'owner',
+		'setting',
+		'status',
+		'create_time',
+		'modify_time',
+		'receive_time'
+    ],
+    "update" =>  [
+		'title',
+		'subtitle',
+		'summary',
+		'content',
+		'tag',
+		'owner',
+		'setting',
+		'status',
+		'modify_time',
+		'receive_time'
+    ]    
+];
+
+$result = do_sync($input);
+echo json_encode($result, JSON_UNESCAPED_UNICODE);
+
+?>

+ 2 - 0
app/sync/table_term.php

@@ -8,8 +8,10 @@ $input = (object) [
     "database" =>  _FILE_DB_TERM_,
     "table" =>  "term",
     "uuid" =>  "guid",
+    "sync_id" =>  ["pali","tag","channal"],
     "modify_time" =>  "modify_time",
     "receive_time" =>  "receive_time",
+	"where"=>"",
     "insert" => [
         'guid',
 		'word',