Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
go-crontab
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
38d5b952
authored
May 13, 2020
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调整etcd任务名
parent
24b0984e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
common/Protocol.go
master/JobMgr.go
common/Protocol.go
View file @
38d5b952
...
...
@@ -12,6 +12,7 @@ import (
// 定时任务
type
Job
struct
{
Name
string
`json:"name"`
// 任务名
JobEtcdName
string
`json:"job_etcd_name"`
// 任务名
Command
string
`json:"command"`
// shell命令
CronExpr
string
`json:"cronExpr"`
// cron表达式
}
...
...
@@ -85,6 +86,7 @@ type SortLogByStartTime struct {
type
CronJobs
struct
{
//Id primitive.ObjectID `bson:"_id"`
JobName
string
`bson:"job_name"`
// 任务名字
JobEtcdName
string
`bson:"job_etcd_name"`
// etcd任务名字
EtcdKey
string
`bson:"etcd_key"`
// etcd key
Node
string
`bson:"node"`
// 所属节点
Group
int64
`bson:"group"`
// 所属分组
...
...
master/JobMgr.go
View file @
38d5b952
...
...
@@ -90,18 +90,19 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
)
// 赋值给job
job
.
Name
=
req
.
FormValue
(
"job_name"
);
job
.
Command
=
req
.
FormValue
(
"command"
);
job
.
CronExpr
=
req
.
FormValue
(
"cron_expr"
);
nodeIp
:=
req
.
FormValue
(
"node"
);
job
.
Name
=
req
.
FormValue
(
"job_name"
)
job
.
JobEtcdName
=
req
.
FormValue
(
"job_etcd_name"
)
job
.
Command
=
req
.
FormValue
(
"command"
)
job
.
CronExpr
=
req
.
FormValue
(
"cron_expr"
)
nodeIp
:=
req
.
FormValue
(
"node"
)
// 任务类型:1-普通任务,2-一次性任务
job_type
,
err
:=
strconv
.
ParseInt
(
req
.
FormValue
(
"job_type"
),
10
,
64
)
if
job_type
==
1
{
jobKey
=
common
.
JOB_SAVE_DIR
+
nodeIp
+
"/"
+
job
.
Name
// etcd的保存key: 目录 + IP + 任务名称
jobKey
=
common
.
JOB_SAVE_DIR
+
nodeIp
+
"/"
+
job
.
JobEtcd
Name
// etcd的保存key: 目录 + IP + 任务名称
}
else
{
jobKey
=
common
.
JOB_ONCE_SAVE_DIR
+
nodeIp
+
"/"
+
job
.
Name
// etcd的保存key: 目录 + IP + 任务名称
jobKey
=
common
.
JOB_ONCE_SAVE_DIR
+
nodeIp
+
"/"
+
job
.
JobEtcd
Name
// etcd的保存key: 目录 + IP + 任务名称
}
// 任务信息json
...
...
@@ -125,6 +126,7 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
// 同步保存到mongo
cron_job_id
:=
req
.
FormValue
(
"id"
)
cronJob
.
JobName
=
req
.
FormValue
(
"job_name"
)
cronJob
.
JobEtcdName
=
req
.
FormValue
(
"job_etcd_name"
)
cronJob
.
EtcdKey
=
jobKey
cronJob
.
Node
=
req
.
FormValue
(
"node"
)
cronJob
.
Group
,
err
=
strconv
.
ParseInt
(
req
.
FormValue
(
"group"
),
10
,
64
)
...
...
@@ -150,8 +152,8 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
cronJob
.
UpdateTime
=
time
.
Now
()
.
Unix
()
// 修改部分值
update
:=
bson
.
M
{
"$set"
:
bson
.
M
{
"node"
:
cronJob
.
Node
,
"group"
:
cronJob
.
Group
,
"command"
:
cronJob
.
Command
,
"cron_expr"
:
cronJob
.
CronExpr
,
"concurrency_num"
:
cronJob
.
ConcurrencyNum
,
"update_time"
:
cronJob
.
UpdateTime
}}
update
:=
bson
.
M
{
"$set"
:
bson
.
M
{
"
job_etcd_name"
:
cronJob
.
JobEtcdName
,
"etcd_key"
:
cronJob
.
EtcdKey
,
"
node"
:
cronJob
.
Node
,
"group"
:
cronJob
.
Group
,
"command"
:
cronJob
.
Command
,
"cron_expr"
:
cronJob
.
CronExpr
,
"concurrency_num"
:
cronJob
.
ConcurrencyNum
,
"
modifier"
:
cronJob
.
Modifier
,
"
update_time"
:
cronJob
.
UpdateTime
}}
objectId
,
err
:=
primitive
.
ObjectIDFromHex
(
cron_job_id
)
_
,
err
=
jobMgr
.
jobCollection
.
UpdateOne
(
context
.
TODO
(),
bson
.
M
{
"_id"
:
objectId
},
update
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment