加入配置只在工作节点上调度

This commit is contained in:
marvzhang
2020-03-11 08:05:37 +08:00
parent 9fc931f136
commit b167107b5c
4 changed files with 23 additions and 5 deletions

View File

@@ -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) // 首页统计数据

View File

@@ -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{

View File

@@ -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
}

View File

@@ -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"
/>
</el-select>
@@ -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
}
}
}