diff --git a/backend/main.go b/backend/main.go index 8b7af36f..8819c0da 100644 --- a/backend/main.go +++ b/backend/main.go @@ -243,16 +243,16 @@ func main() { { authGroup.GET("/variables", routes.GetVariableList) // 列表 authGroup.PUT("/variable", routes.PutVariable) // 新增 - authGroup.POST("/variable/:id", routes.PostVariable) //修改 - authGroup.DELETE("/variable/:id", routes.DeleteVariable) //删除 + authGroup.POST("/variable/:id", routes.PostVariable) // 修改 + authGroup.DELETE("/variable/:id", routes.DeleteVariable) // 删除 } // 项目 { authGroup.GET("/projects", routes.GetProjectList) // 列表 authGroup.GET("/projects/tags", routes.GetProjectTags) // 项目标签 - authGroup.PUT("/projects", routes.PutProject) //修改 + authGroup.PUT("/projects", routes.PutProject) // 修改 authGroup.POST("/projects/:id", routes.PostProject) // 新增 - authGroup.DELETE("/projects/:id", routes.DeleteProject) //删除 + authGroup.DELETE("/projects/:id", routes.DeleteProject) // 删除 } // 统计数据 authGroup.GET("/stats/home", routes.GetHomeStats) // 首页统计数据 diff --git a/backend/routes/setting.go b/backend/routes/setting.go index 83976455..66ee7128 100644 --- a/backend/routes/setting.go +++ b/backend/routes/setting.go @@ -9,6 +9,7 @@ import ( type SettingBody struct { AllowRegister string `json:"allow_register"` EnableTutorial string `json:"enable_tutorial"` + RunOnMaster string `json:"run_on_master"` } func GetVersion(c *gin.Context) { @@ -25,6 +26,7 @@ func GetSetting(c *gin.Context) { body := SettingBody{ AllowRegister: viper.GetString("setting.allowRegister"), EnableTutorial: viper.GetString("setting.enableTutorial"), + RunOnMaster: viper.GetString("setting.runOnMaster"), } c.JSON(http.StatusOK, Response{ diff --git a/backend/services/task.go b/backend/services/task.go index 55c37140..469fa8da 100644 --- a/backend/services/task.go +++ b/backend/services/task.go @@ -853,10 +853,18 @@ func SendNotifications(u model.User, t model.Task, s model.Spider) { } func InitTaskExecutor() error { + // 构造任务执行器 c := cron.New(cron.WithSeconds()) Exec = &Executor{ Cron: c, } + + // 如果不允许主节点运行任务,则跳过 + if model.IsMaster() && viper.GetString("setting.runOnMaster") == "N" { + return nil + } + + // 运行定时任务 if err := Exec.Start(); err != nil { return err } diff --git a/frontend/src/components/Common/CrawlConfirmDialog.vue b/frontend/src/components/Common/CrawlConfirmDialog.vue index 93d62d9d..001be5b5 100644 --- a/frontend/src/components/Common/CrawlConfirmDialog.vue +++ b/frontend/src/components/Common/CrawlConfirmDialog.vue @@ -29,7 +29,7 @@ v-for="op in nodeList" :key="op._id" :value="op._id" - :disabled="op.status !== 'online'" + :disabled="isNodeDisabled(op)" :label="op.name" /> @@ -139,6 +139,9 @@ export default { ...mapState('spider', [ 'spiderForm' ]), + ...mapState('setting', [ + 'setting' + ]), isConfirmDisabled () { if (this.isLoading) return true if (!this.isAllowDisclaimer) return true @@ -291,6 +294,11 @@ export default { onParametersConfirm (value) { this.form.param = value this.isParametersVisible = false + }, + isNodeDisabled (node) { + if (node.status !== 'online') return true + if (node.is_master && this.setting.run_on_master === 'N') return true + return false } } }