|
|
|
@ -16,18 +16,9 @@ func (c *Client) Run(ctx context.Context, info jobs_gorm_model.Task, status int,
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求函数记录
|
|
|
|
|
err := c.db.gormClient.Db.Create(&jobs_gorm_model.TaskLog{
|
|
|
|
|
TaskId: info.Id,
|
|
|
|
|
StatusCode: status,
|
|
|
|
|
Desc: result,
|
|
|
|
|
Version: c.config.sdkVersion,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.Create]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if status == 0 {
|
|
|
|
|
err = c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
switch status {
|
|
|
|
|
case 0:
|
|
|
|
|
err := c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
Select("run_id", "result", "next_run_time").
|
|
|
|
|
Updates(jobs_gorm_model.Task{
|
|
|
|
|
RunId: runId,
|
|
|
|
@ -35,14 +26,12 @@ func (c *Client) Run(ctx context.Context, info jobs_gorm_model.Task, status int,
|
|
|
|
|
NextRunTime: gotime.Current().AfterSeconds(info.Frequency).Time,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.0.EditTask]:%s", err.Error())
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.0]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 任务
|
|
|
|
|
if status == CodeSuccess {
|
|
|
|
|
case CodeSuccess:
|
|
|
|
|
// 执行成功
|
|
|
|
|
err = c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
err := c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
Select("status_desc", "number", "run_id", "updated_ip", "result", "next_run_time").
|
|
|
|
|
Updates(jobs_gorm_model.Task{
|
|
|
|
|
StatusDesc: "执行成功",
|
|
|
|
@ -53,12 +42,11 @@ func (c *Client) Run(ctx context.Context, info jobs_gorm_model.Task, status int,
|
|
|
|
|
NextRunTime: gotime.Current().AfterSeconds(info.Frequency).Time,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeSuccess.EditTask]:%s", err.Error())
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeSuccess]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if status == CodeEnd {
|
|
|
|
|
case CodeEnd:
|
|
|
|
|
// 执行成功、提前结束
|
|
|
|
|
err = c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
err := c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
Select("status", "status_desc", "number", "updated_ip", "result", "next_run_time").
|
|
|
|
|
Updates(jobs_gorm_model.Task{
|
|
|
|
|
Status: TASK_SUCCESS,
|
|
|
|
@ -69,12 +57,11 @@ func (c *Client) Run(ctx context.Context, info jobs_gorm_model.Task, status int,
|
|
|
|
|
NextRunTime: gotime.Current().Time,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeEnd.EditTask]:%s", err.Error())
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeEnd]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if status == CodeError {
|
|
|
|
|
case CodeError:
|
|
|
|
|
// 执行失败
|
|
|
|
|
err = c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
err := c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
Select("status_desc", "number", "run_id", "updated_ip", "result", "next_run_time").
|
|
|
|
|
Updates(jobs_gorm_model.Task{
|
|
|
|
|
StatusDesc: "执行失败",
|
|
|
|
@ -85,36 +72,22 @@ func (c *Client) Run(ctx context.Context, info jobs_gorm_model.Task, status int,
|
|
|
|
|
NextRunTime: gotime.Current().AfterSeconds(info.Frequency).Time,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeError.EditTask]:%s", err.Error())
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.CodeError]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if info.MaxNumber != 0 {
|
|
|
|
|
if info.Number+1 >= info.MaxNumber {
|
|
|
|
|
// 关闭执行
|
|
|
|
|
err = c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
err := c.EditTask(c.db.gormClient.Db, info.Id).
|
|
|
|
|
Select("status").
|
|
|
|
|
Updates(jobs_gorm_model.Task{
|
|
|
|
|
Status: TASK_TIMEOUT,
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.TASK_TIMEOUT.EditTask]:%s", err.Error())
|
|
|
|
|
c.zapLog.WithTraceId(ctx).Sugar().Errorf("[gojobs.Run.TASK_TIMEOUT]:%s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RunAddLog 任务执行日志
|
|
|
|
|
func (c *Client) RunAddLog(ctx context.Context, id uint, runId string) error {
|
|
|
|
|
return c.db.gormClient.Db.Create(&jobs_gorm_model.TaskLogRun{
|
|
|
|
|
TaskId: id,
|
|
|
|
|
RunId: runId,
|
|
|
|
|
InsideIp: c.config.systemInsideIp,
|
|
|
|
|
OutsideIp: c.config.systemOutsideIp,
|
|
|
|
|
Os: c.config.systemOs,
|
|
|
|
|
Arch: c.config.systemArch,
|
|
|
|
|
Gomaxprocs: c.config.systemCpuQuantity,
|
|
|
|
|
GoVersion: c.config.goVersion,
|
|
|
|
|
SdkVersion: c.config.sdkVersion,
|
|
|
|
|
MacAddrs: c.config.systemMacAddrS,
|
|
|
|
|
}).Error
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|