From dd4da4ccb33473af3a5bb93079b3dc079d51cadd Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 3 Feb 2020 15:27:00 +0800 Subject: [PATCH 1/3] fixed unable to save settings error --- frontend/src/views/setting/Setting.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/setting/Setting.vue b/frontend/src/views/setting/Setting.vue index 27e79b9c..682b9cb0 100644 --- a/frontend/src/views/setting/Setting.vue +++ b/frontend/src/views/setting/Setting.vue @@ -197,7 +197,15 @@ export default { ...mapState('user', [ 'globalVariableList', 'globalVariableForm' - ]) + ]), + userInfoStr () { + return JSON.stringify(this.userInfo) + } + }, + watch: { + userInfoStr () { + this.saveUserInfo() + } }, methods: { deleteGlobalVariableHandle (id) { From 81d9495148fd1ad1107d497a3c281b7a32166846 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 3 Feb 2020 15:29:59 +0800 Subject: [PATCH 2/3] fixed unable to save settings error --- frontend/src/views/setting/Setting.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/setting/Setting.vue b/frontend/src/views/setting/Setting.vue index 682b9cb0..fb74d41c 100644 --- a/frontend/src/views/setting/Setting.vue +++ b/frontend/src/views/setting/Setting.vue @@ -41,6 +41,13 @@ + +
+ + {{$t('Save')}} + +
+
@@ -77,6 +84,13 @@ + +
+ + {{$t('Save')}} + +
+
@@ -197,10 +211,7 @@ export default { ...mapState('user', [ 'globalVariableList', 'globalVariableForm' - ]), - userInfoStr () { - return JSON.stringify(this.userInfo) - } + ]) }, watch: { userInfoStr () { From 23f0b0c9e22b09422fe818f46d00f1f15470cf67 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 3 Feb 2020 16:08:43 +0800 Subject: [PATCH 3/3] fixed unable to sync spiders to nodes error --- backend/services/spider.go | 2 ++ backend/services/spider_handler/spider.go | 14 ++++++++++---- backend/utils/file.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/services/spider.go b/backend/services/spider.go index 36872460..fb785d85 100644 --- a/backend/services/spider.go +++ b/backend/services/spider.go @@ -368,6 +368,8 @@ func InitSpiderService() error { } } + // 发布所有爬虫 + PublishAllSpiders() } return nil diff --git a/backend/services/spider_handler/spider.go b/backend/services/spider_handler/spider.go index cd8a1dbe..ddc94b57 100644 --- a/backend/services/spider_handler/spider.go +++ b/backend/services/spider_handler/spider.go @@ -4,6 +4,7 @@ import ( "crawlab/database" "crawlab/model" "crawlab/utils" + "fmt" "github.com/apex/log" "github.com/globalsign/mgo/bson" "github.com/satori/go.uuid" @@ -25,7 +26,7 @@ type SpiderSync struct { func (s *SpiderSync) CreateMd5File(md5 string) { path := filepath.Join(viper.GetString("spider.path"), s.Spider.Name) - utils.CreateFilePath(path) + utils.CreateDirPath(path) fileName := filepath.Join(path, Md5File) file := utils.OpenFile(fileName) @@ -66,10 +67,14 @@ func (s *SpiderSync) RemoveSpiderFile() { // 检测是否已经下载中 func (s *SpiderSync) CheckDownLoading(spiderId string, fileId string) (bool, string) { key := s.GetLockDownloadKey(spiderId) - if _, err := database.RedisClient.HGet("spider", key); err == nil { - return true, key + key2, err := database.RedisClient.HGet("spider", key) + if err != nil { + return false, key2 } - return false, key + if key2 == "" { + return false, key2 + } + return true, key2 } // 下载爬虫 @@ -78,6 +83,7 @@ func (s *SpiderSync) Download() { fileId := s.Spider.FileId.Hex() isDownloading, key := s.CheckDownLoading(spiderId, fileId) if isDownloading { + log.Infof(fmt.Sprintf("spider is already being downloaded, spider id: %s", s.Spider.Id.Hex())) return } else { _ = database.RedisClient.HSet("spider", key, key) diff --git a/backend/utils/file.go b/backend/utils/file.go index bfe92bd3..072930cf 100644 --- a/backend/utils/file.go +++ b/backend/utils/file.go @@ -55,7 +55,7 @@ func OpenFile(fileName string) *os.File { } // 创建文件夹 -func CreateFilePath(filePath string) { +func CreateDirPath(filePath string) { if !Exists(filePath) { if err := os.MkdirAll(filePath, os.ModePerm); err != nil { log.Errorf("create file error: %s, file_path: %s", err.Error(), filePath)