Skip to content

Commit

Permalink
Feature/cronjob (#12)
Browse files Browse the repository at this point in the history
* feat: 新增文件读取接口
* 支持任务手动下发和状态回显及日志回显
* 对接juno任务下发和执行
  • Loading branch information
link-duan committed Sep 4, 2020
1 parent 2ed39de commit 9c93611
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 145 deletions.
24 changes: 14 additions & 10 deletions config/config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[plugin]
[plugin.regProxy]
# 注册中心地址
endpoints=["127.0.0.1:2379"]
timeout="3s"
secure=false
enable = true
[plugin.regProxy.prometheus]
enable = true
Expand All @@ -19,9 +15,6 @@
enable=false
dsn=""
secure=false
[plugin.confProxy.etcd]
enable=true
endpoints=["127.0.0.1:2379"]
[plugin.supervisor]
enable = true
dir = "/etc/supervisor/conf.d"
Expand All @@ -48,13 +41,24 @@
enable = false
[plugin.worker]
reqTimeout = 10
etcdConfigKey = "myetcd"
[jupiter.etcdv3.myetcd]
endpoints = ["mps.longsys.com:2379"]

# service registry etcd
[jupiter.etcdv3.register]
endpoints = ["127.0.0.1:2379"]
connectTimeout = "10s"

# default etcd (config-publish / cronjob-dispatch / etc...)
[jupiter.etcdv3.default]
endpoints = ["127.0.0.1:2379"]
connectTimeout = "10s"

[jupiter.logger.default]
name = "default"
debug = true
[jupiter.logger.cronjob]
name = "cronjob.log"
level = "debug"

[jupiter.server]
[jupiter.server.grpc]
host = "0.0.0.0"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/nats-io/nats-server/v2 v2.1.6 // indirect
github.com/nats-io/nats.go v1.9.2
github.com/robfig/cron/v3 v3.0.1
github.com/sony/sonyflake v1.0.0
github.com/stretchr/testify v1.6.1
github.com/uber-go/atomic v1.4.0
github.com/yangchenxing/go-nginx-conf-parser v0.0.0-20190110023421-0d59f1b7a3f6
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ github.com/creasty/defaults v1.3.0/go.mod h1:CIEEvs7oIVZm30R8VxtFJs+4k201gReYyuY
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/denisenkom/go-mssqldb v0.0.0-20180620032804-94c9c97e8c9f/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
Expand Down Expand Up @@ -489,6 +490,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM=
github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (eng *Engine) startConfProxy() error {
// startRegProxy start app regist proxy plugin
func (eng *Engine) startRegProxy() error {
eng.regProxy = regProxy.StdConfig("regProxy").Build()
if eng.regProxy == nil {
return nil
}

if err := eng.regProxy.Start(); err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/job/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ var (
)

const (
JobsKeyPrefix = "/worker/cmd/" // cronsun task路径
OnceKeyPrefix = "/worker/once/" // 马上执行任务路径
LockKeyPrefix = "/worker/lock/" // job lock 路径
ProcKeyPrefix = "/worker/proc/" // 正在运行的Process
JobsKeyPrefix = "/juno/cronjob/job/" // job prefix
OnceKeyPrefix = "/juno/cronjob/once/" // job that run immediately
LockKeyPrefix = "/juno/cronjob/lock/" // job lock (only for single-node mode job)
ProcKeyPrefix = "/juno/cronjob/proc/" // running process
ResultKeyPrefix = "/juno/cronjob/result/" // task result (logs and status)
)

type Config struct {
Expand Down Expand Up @@ -49,6 +50,7 @@ func StdConfig(key string) *Config {
panic(err)
}

config.logger = xlog.StdConfig("cronjob").Build()
return config
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/job/exec_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package job

import "syscall"

func makeCmdAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setpgid: true,
}
}

func killProcess(pid int) error {
return syscall.Kill(-pid, syscall.SIGKILL)
}
16 changes: 16 additions & 0 deletions pkg/job/exec_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package job

import (
"os/exec"
"strconv"
"syscall"
)

func makeCmdAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{}
}

func killProcess(pid int) error {
return exec.Command("taskkill", "/T", "/F", "/PID", strconv.Itoa(pid)).Run()
}

0 comments on commit 9c93611

Please sign in to comment.