Compare commits

...
13 Commits
15 changed files with 192 additions and 19 deletions
+13 -9
View File
@@ -1,18 +1,22 @@
FROM golang:1.10-alpine as builder
WORKDIR /go/src/github.com/ouqiang/gocron
COPY . .
FROM golang:1.15-alpine as builder
RUN apk update \
&& apk add --no-cache git ca-certificates make bash nodejs yarn
&& apk add --no-cache git ca-certificates make bash yarn nodejs
RUN make install-vue \
RUN go env -w GO111MODULE=on && \
go env -w GOPROXY=https://goproxy.cn,direct
WORKDIR /app
RUN git clone https://github.com/ouqiang/gocron.git \
&& cd gocron \
&& yarn config set ignore-engines true \
&& make install-vue \
&& make build-vue \
&& make statik \
&& CGO_ENABLED=0 make gocron
FROM alpine:3.7
FROM alpine:3.12
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S app \
@@ -22,7 +26,7 @@ RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
WORKDIR /app
COPY --from=builder /go/src/github.com/ouqiang/gocron/bin/gocron .
COPY --from=builder /app/gocron/bin/gocron .
RUN chown -R app:app ./
+3 -1
View File
@@ -55,8 +55,10 @@
4. 浏览器访问 http://localhost:5920
### 源码安装
- 安装Go 1.9+
- 安装Go 1.11+
- `go get -d github.com/ouqiang/gocron`
- `export GO111MODULE=on`
- 编译 `make`
- 启动
* gocron `./bin/gocron web`
+1
View File
@@ -62,6 +62,7 @@ github.com/klauspost/compress v1.5.0 h1:iDac0ZKbmSA4PRrRuXXjZL8C7UoJan8oBYxXkMzE
github.com/klauspost/compress v1.5.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+4 -1
View File
@@ -16,19 +16,22 @@ const slackTemplate = `
任务名称: {{.TaskName}}
状态: {{.Status}}
执行结果: {{.Result}}
备注: {{.Remark}}
`
const emailTemplate = `
任务ID: {{.TaskId}}
任务名称: {{.TaskName}}
状态: {{.Status}}
执行结果: {{.Result}}
备注: {{.Remark}}
`
const webhookTemplate = `
{
"task_id": "{{.TaskId}}",
"task_name": "{{.TaskName}}",
"status": "{{.Status}}",
"result": "{{.Result}}"
"result": "{{.Result}}",
"remark": "{{.Remark}}"
}
`
+3
View File
@@ -129,6 +129,9 @@ func (task *Task) ActiveListByHostId(hostId int16) ([]Task, error) {
if err != nil {
return nil, err
}
if len(taskIds) == 0 {
return nil, nil
}
list := make([]Task, 0)
err = Db.Where("status = ? AND level = ?", Enabled, TaskLevelParent).
In("id", taskIds...).
+1
View File
@@ -69,6 +69,7 @@ func parseNotifyTemplate(notifyTemplate string, msg Message) string {
"TaskName": msg["name"],
"Status": msg["status"],
"Result": msg["output"],
"Remark": msg["remark"],
})
return buf.String()
+2 -1
View File
@@ -53,7 +53,6 @@ func (p *GRPCPool) Get(addr string) (rpc.TaskClient, error) {
if err != nil {
return nil, err
}
p.conns[addr] = client
return client.rpcClient, nil
}
@@ -115,5 +114,7 @@ func (p *GRPCPool) factory(addr string) (*Client, error) {
rpcClient: rpc.NewTaskClient(conn),
}
p.conns[addr] = client
return client, nil
}
+3 -5
View File
@@ -25,11 +25,9 @@ var keepAlivePolicy = keepalive.EnforcementPolicy{
}
var keepAliveParams = keepalive.ServerParameters{
MaxConnectionIdle: 1 * time.Minute,
MaxConnectionAge: 2 * time.Hour,
MaxConnectionAgeGrace: 3 * time.Hour,
Time: 30 * time.Second,
Timeout: 3 * time.Second,
MaxConnectionIdle: 30 * time.Second,
Time: 30 * time.Second,
Timeout: 3 * time.Second,
}
func (s Server) Run(ctx context.Context, req *pb.TaskRequest) (*pb.TaskResponse, error) {
+1 -1
View File
@@ -251,7 +251,7 @@ func changeStatus(ctx *macaron.Context, status models.Status) string {
json := utils.JsonResponse{}
taskModel := new(models.Task)
_, err := taskModel.Update(id, models.CommonMap{
"Status": status,
"status": status,
})
if err != nil {
return json.CommonFailure(utils.FailureContent, err)
+1 -1
View File
@@ -163,7 +163,7 @@ func changeStatus(ctx *macaron.Context, status models.Status) string {
json := utils.JsonResponse{}
userModel := new(models.User)
_, err := userModel.Update(id, models.CommonMap{
"Status": status,
"status": status,
})
if err != nil {
return json.CommonFailure(utils.FailureContent, err)
+1
View File
@@ -456,6 +456,7 @@ func SendNotification(taskModel models.Task, taskResult TaskResult) {
"output": taskResult.Result,
"status": statusName,
"task_id": taskModel.Id,
"remark": taskModel.Remark,
}
notify.Push(msg)
}
+17
View File
@@ -0,0 +1,17 @@
FROM alpine:3.7
ENV GOCRON_AGENT_VERSION=v1.5
RUN apk add --no-cache ca-certificates tzdata bash \
&& mkdir -p /app \
&& wget -P /tmp https://github.com/ouqiang/gocron/releases/download/${GOCRON_AGENT_VERSION}/gocron-node-${GOCRON_AGENT_VERSION}-linux-amd64.tar.gz \
&& cd /tmp \
&& tar zvxf gocron-node-${GOCRON_AGENT_VERSION}-linux-amd64.tar.gz \
&& mv /tmp/gocron-node-linux-amd64/gocron-node /app \
&& rm -rf /tmp/* \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
WORKDIR /app
EXPOSE 5921
ENTRYPOINT ["/app/gocron-node", "-allow-root"]
+38
View File
@@ -0,0 +1,38 @@
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: gocron-agent
namespace: kube-system
spec:
selector:
matchLabels:
daemon: gocron-agent
template:
metadata:
labels:
daemon: gocron-agent
name: gocron-agent
spec:
containers:
- name: gocron-agent
image: crontab-agent:0.5
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5921
hostPort: 5921
name: gocron-agent
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/log
name: syslog
hostNetwork: true
hostPID: true
restartPolicy: Always
volumes:
- hostPath:
path: /var/log
type: Directory
name: syslog
+51
View File
@@ -0,0 +1,51 @@
# 改为用StatefulSet部署,把配置目录挂载到外置存储,以防container down后重启
# 如果使用历史数据库,需要先配置安装,然后在conf目录下创建install.lock文件,最后重启进程即可
#
---
apiVersion: v1
kind: Service
metadata:
name: gocron
labels:
app: gocron
spec:
ports:
- port: 5920
name: gocron
type: NodePort
selector:
app: gocron
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: gocron
spec:
serviceName: "gocron"
replicas: 1
template:
metadata:
labels:
app: gocron
spec:
securityContext:
fsGroup: 1000
terminationGracePeriodSeconds: 10
containers:
- name: gocron
image: ouqg/gocron:latest
ports:
- containerPort: 5920
name: gocron
volumeMounts:
- name: gocron-vol
mountPath: /app/conf
volumeClaimTemplates:
- metadata:
name: gocron-vol
spec:
storageClassName: rbd
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 100Mi
+53
View File
@@ -0,0 +1,53 @@
---
apiVersion: v1
kind: Service
metadata:
name: mysql
#namespace: storage
labels:
app: mysql
spec:
ports:
- port: 3306
name: mysql
clusterIP: None
selector:
app: mysql
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mysql
#namespace: storage
spec:
serviceName: "mysql"
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mysql
image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
value: password
- name: MYSQL_DATABASE
value: crontab
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-vol
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mysql-vol
spec:
storageClassName: rbd # 需要storageClassName
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 100Gi