Commit 45f4bace by 孙龙

up

parent 48e41ace
......@@ -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 (
......
......@@ -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 (
......
......@@ -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
......
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
}
......
......@@ -15,10 +15,7 @@
"jobLogBatchSize": 100,
"日志自动提交超时": "在批次未达到阀值之前, 超时会自动提交batch",
"jobLogCommitTimeout": 1000,
"etcdUserName":"root",
"etcdPasswd":"huntmon66499",
"jobLogCommitTimeout": 10,
"mongodbDatabases": "ichunt",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment