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
45f4bace
authored
Aug 27, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
48e41ace
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
18 deletions
master/Config.go
worker/Config.go
worker/Executor.go
worker/LogSink.go
worker/main/worker.json.bak
master/Config.go
View file @
45f4bace
...
...
@@ -15,9 +15,9 @@ type Config struct {
WebRoot
string
`json:"webroot"`
MongodbUri
string
`json:"mongodbUri"`
MongodbConnectTimeout
int
`json:"mongodbConnectTimeout"`
EtcdUserName
string
`json"etcdUserName"`
EtcdPasswd
string
`json"etcdPasswd"`
MondbDatabases
string
`json"mongodbDatabases"`
EtcdUserName
string
`json
:
"etcdUserName"`
EtcdPasswd
string
`json
:
"etcdPasswd"`
MondbDatabases
string
`json
:
"mongodbDatabases"`
}
var
(
...
...
worker/Config.go
View file @
45f4bace
...
...
@@ -12,11 +12,11 @@ type Config struct {
MongodbUri
string
`json:"mongodbUri"`
MongodbConnectTimeout
int
`json:"mongodbConnectTimeout"`
JobLogBatchSize
int
`json:"jobLogBatchSize"`
JobLogCommitTimeout
int
`json"jobLogCommitTimeout"`
ExecCommand
string
`json"execCommand"`
EtcdUserName
string
`json"etcdUserName"`
EtcdPasswd
string
`json"etcdPasswd"`
MondbDatabases
string
`json"mongodbDatabases"`
JobLogCommitTimeout
int
`json
:
"jobLogCommitTimeout"`
ExecCommand
string
`json
:
"execCommand"`
EtcdUserName
string
`json
:
"etcdUserName"`
EtcdPasswd
string
`json
:
"etcdPasswd"`
MondbDatabases
string
`json
:
"mongodbDatabases"`
}
var
(
...
...
worker/Executor.go
View file @
45f4bace
...
...
@@ -2,6 +2,7 @@ package worker
import
(
"errors"
"fmt"
"go-crontab/common"
"math/rand"
"os/exec"
...
...
@@ -48,14 +49,12 @@ func (executor *Executor) ExecuteJob(info *common.JobExecuteInfo) {
err
=
jobLock
.
TryLock
()
defer
jobLock
.
Unlock
()
if
err
!=
nil
{
// 上锁失败
result
.
Err
=
err
result
.
EndTime
=
time
.
Now
()
}
else
{
// 上锁成功后,重置任务启动时间
result
.
StartTime
=
time
.
Now
()
if
ok
:=
strings
.
HasSuffix
(
info
.
Job
.
Command
,
".sh"
);
!
ok
{
result
.
EndTime
=
time
.
Now
()
result
.
Output
=
[]
byte
(
"该命令不是以.sh结尾的文件,无法执行"
)
...
...
@@ -67,7 +66,7 @@ func (executor *Executor) ExecuteJob(info *common.JobExecuteInfo) {
// 执行并捕获输出
output
,
err
=
cmd
.
CombinedOutput
()
fmt
.
Println
(
string
(
output
))
// 记录任务结束时间
result
.
EndTime
=
time
.
Now
()
result
.
Output
=
output
...
...
worker/LogSink.go
View file @
45f4bace
package
worker
import
(
"go.mongodb.org/mongo-driver/mongo"
"go-crontab/common"
"context"
"github.com/ichunt2019/logger"
"go-crontab/common"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
...
...
@@ -23,7 +24,7 @@ var (
// 批量写入日志
func
(
logSink
*
LogSink
)
saveLogs
(
batch
*
common
.
LogBatch
)
{
logSink
.
logCollection
.
InsertMany
(
context
.
TODO
(),
batch
.
Logs
)
logSink
.
logCollection
.
InsertMany
(
context
.
TODO
(),
batch
.
Logs
)
}
// 日志存储协程
...
...
@@ -85,6 +86,7 @@ func InitLogSink() (err error) {
clientOptions
:=
options
.
Client
()
.
ApplyURI
(
G_config
.
MongodbUri
)
if
client
,
err
=
mongo
.
Connect
(
context
.
TODO
(),
clientOptions
);
err
!=
nil
{
logger
.
Error
(
"mongodb数据库连接失败:%s"
,
err
)
return
}
...
...
worker/main/worker.json.bak
View file @
45f4bace
...
...
@@ -15,10 +15,7 @@
"jobLogBatchSize": 100,
"日志自动提交超时": "在批次未达到阀值之前, 超时会自动提交batch",
"jobLogCommitTimeout": 1000,
"etcdUserName":"root",
"etcdPasswd":"huntmon66499",
"jobLogCommitTimeout": 10,
"mongodbDatabases": "ichunt",
...
...
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