Răsfoiți Sursa

sendListNum方法修改

maxiaoshan 2 ani în urmă
părinte
comite
0f12459eca
2 a modificat fișierele cu 14 adăugiri și 10 ștergeri
  1. 2 2
      src/spider/handler.go
  2. 12 8
      src/spider/script.go

+ 2 - 2
src/spider/handler.go

@@ -426,6 +426,7 @@ func UpdateSpiderByCodeState(code, state string) (bool, error) {
 					if ok {
 						if !sp.Stop { //脚本未执行
 							sp.Stop = true
+							sp.ScriptStop = true //专用于findlist心跳记录
 						}
 					}
 					as.Delete(code)
@@ -667,7 +668,7 @@ func UpdateSpiderByCodeState(code, state string) (bool, error) {
 					}
 				}
 				//2、Allspiders2对应7100、7110、7400上架采集三级页数据(Allspiders2三级页爬虫集合)
-				if util.Config.Modal == 1 { //高性能老模式不根据列表页数据采三级页(7000、7410)
+				if util.Config.Modal == 1 {
 					//Allspiders2
 					if spd2, ok2 := Allspiders2.Load(k); ok2 { //对应脚本已存在,更新
 						sp2 := spd2.(*Spider)
@@ -690,7 +691,6 @@ func UpdateSpiderByCodeState(code, state string) (bool, error) {
 							sp2.UserEmail = v["createuseremail"]
 							sp2.MUserName = v["modifyuser"]
 							sp2.MUserEmail = v["modifyemail"]
-							sp2.Stop = false
 							sp2.IsMainThread = true         //多线程采集时使用
 							go sp2.DownloadHighDetail(true) //根据列表页数据下载三级页
 							Allspiders2.Store(k, sp2)

+ 12 - 8
src/spider/script.go

@@ -42,10 +42,11 @@ import (
 
 //脚本
 type Script struct {
-	SCode, ScriptFile string
-	Encoding          string
-	Userproxy         bool
 	//Ishttps            bool
+	SCode, ScriptFile  string
+	Encoding           string
+	Userproxy          bool
+	ScriptStop         bool   //记录爬虫是否下架,用于判断心跳
 	ErrorNum           int32  //错误数
 	Downloader         string //下载器
 	TotalRequestNum    int32  //总请求次数
@@ -499,11 +500,14 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
 	}))
 	//推送列表页下载数据量
 	s.L.SetGlobal("sendListNum", s.L.NewFunction(func(S *lua.LState) int {
-		index := S.ToInt(-2)
-		table := S.ToTable(-1)
-		list := util.TableToMap(table)
-		if index <= 1 && len(list) > 0 {
-			UpdateHeart(*site, *channel, code, *user, "findlist") //记录列表页实际采集数据量心跳
+		if !s.ScriptStop { //非下架状态,记录心跳
+			index := S.ToInt(-2)
+			if index == 1 {
+				table := S.ToTable(-1)
+				if table.Len() > 0 {
+					UpdateHeart(*site, *channel, code, *user, "findlist") //记录列表页实际采集数据量心跳
+				}
+			}
 		}
 		return 1
 	}))