maxiaoshan 2 år sedan
förälder
incheckning
f973171217
2 ändrade filer med 10 tillägg och 13 borttagningar
  1. 4 4
      src/spider/handler.go
  2. 6 9
      src/spider/script.go

+ 4 - 4
src/spider/handler.go

@@ -418,7 +418,7 @@ func UpdateSpiderByCodeState(code, state string) (bool, error) {
 		if util.Config.Working == 1 { //队列模式
 			for i, as := range []sync.Map{Allspiders, Allspiders2} {
 				if i == 1 && util.Config.Modal == 0 { //队列模式原始模式采集Allspiders2无用(7700下架爬虫)
-					continue
+					break
 				}
 				tmp, b := as.Load(code)
 				if b {
@@ -426,7 +426,6 @@ func UpdateSpiderByCodeState(code, state string) (bool, error) {
 					if ok {
 						if !sp.Stop { //脚本未执行
 							sp.Stop = true
-							sp.ScriptStop = true //专用于findlist心跳记录
 						}
 					}
 					as.Delete(code)
@@ -1380,8 +1379,9 @@ func SaveHeartInfo() {
 	num := 0
 	SpiderHeart.Range(func(key, value interface{}) bool {
 		code := key.(string)
-		heart, ok := value.(*Heart)
-		if ok {
+		heart, heartOk := value.(*Heart)
+		_, spiderOk := LoopListPath.Load(code)
+		if heartOk && spiderOk {
 			num++
 			update := []map[string]interface{}{}
 			update = append(update, map[string]interface{}{"code": code})

+ 6 - 9
src/spider/script.go

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