mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-12 14:52:07 +08:00
优化功能,通知功能,任务功能
This commit is contained in:
@@ -4,6 +4,10 @@ import (
|
||||
"fmt"
|
||||
"pandax/apps/job/entity"
|
||||
"pandax/apps/job/services"
|
||||
|
||||
logEntity "pandax/apps/log/entity"
|
||||
logServices "pandax/apps/log/services"
|
||||
|
||||
"pandax/base/global"
|
||||
"pandax/base/httpclient"
|
||||
"sync"
|
||||
@@ -23,6 +27,7 @@ var Crontab = new(cron.Cron)
|
||||
type JobCore struct {
|
||||
InvokeTarget string
|
||||
Name string
|
||||
JobGroup string
|
||||
JobId int64
|
||||
EntryId int
|
||||
CronExpression string // 任务表达式
|
||||
@@ -45,7 +50,6 @@ func (e *ExecJob) Run() {
|
||||
startTime := time.Now()
|
||||
var obj = jobList[e.InvokeTarget]
|
||||
if obj == nil {
|
||||
global.Log.Warn("[Job] ExecJob Run job nil")
|
||||
if e.MisfirePolicy == "2" {
|
||||
Remove(e.cron, e.EntryId)
|
||||
}
|
||||
@@ -53,22 +57,16 @@ func (e *ExecJob) Run() {
|
||||
}
|
||||
err := CallExec(obj.(JobsExec), e.Args)
|
||||
if err != nil {
|
||||
// 如果失败暂停一段时间重试
|
||||
fmt.Println(time.Now().Format(timeFormat), " [ERROR] mission failed! ", err)
|
||||
if e.MisfirePolicy == "2" {
|
||||
Remove(e.cron, e.EntryId)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 结束时间
|
||||
endTime := time.Now()
|
||||
|
||||
// 执行时间
|
||||
latencyTime := endTime.Sub(startTime)
|
||||
//TODO: 待完善部分
|
||||
//str := time.Now().Format(timeFormat) + " [INFO] JobCore " + string(e.EntryId) + "exec success , spend :" + latencyTime.String()
|
||||
//ws.SendAll(str)
|
||||
global.Log.Info("[Job] JobCore %s exec success , spend :%v", e.Name, latencyTime)
|
||||
latencyTime := time.Now().Sub(startTime)
|
||||
|
||||
logInfo := fmt.Sprintf("任务运行总耗时 %f", latencyTime.Seconds())
|
||||
logServices.LogJobModelDao.Insert(logEntity.LogJob{Name: e.Name, JobGroup: e.JobGroup, EntryId: e.EntryId, InvokeTarget: e.InvokeTarget, LogInfo: logInfo, Status: "0"})
|
||||
// 执行一次
|
||||
if e.MisfirePolicy == "1" {
|
||||
Remove(e.cron, e.EntryId)
|
||||
@@ -90,13 +88,11 @@ LOOP:
|
||||
goto LOOP
|
||||
}
|
||||
}
|
||||
// 结束时间
|
||||
endTime := time.Now()
|
||||
|
||||
// 执行时间
|
||||
latencyTime := endTime.Sub(startTime)
|
||||
latencyTime := time.Now().Sub(startTime)
|
||||
|
||||
global.Log.Infof("[Job] JobCore %s exec success , spend :%v", h.Name, latencyTime)
|
||||
logInfo := fmt.Sprintf("任务运行总耗时 %f", latencyTime.Seconds())
|
||||
logServices.LogJobModelDao.Insert(logEntity.LogJob{Name: h.Name, JobGroup: h.JobGroup, EntryId: h.EntryId, InvokeTarget: h.InvokeTarget, LogInfo: logInfo, Status: "0"})
|
||||
if h.MisfirePolicy == "1" {
|
||||
Remove(h.cron, h.EntryId)
|
||||
}
|
||||
@@ -105,8 +101,8 @@ LOOP:
|
||||
|
||||
func Setup() {
|
||||
Crontab = NewWithSeconds()
|
||||
// 获取系统job 0是默认,1是系统
|
||||
jl := services.JobModelDao.FindList(entity.SysJob{JobGroup: "1"})
|
||||
// 获取系统job SYSTEM是系统
|
||||
jl := services.JobModelDao.FindList(entity.SysJob{JobGroup: "SYSTEM"})
|
||||
jobList := *jl
|
||||
if len(jobList) == 0 {
|
||||
global.Log.Info(time.Now().Format(timeFormat), " [INFO] JobCore total:0")
|
||||
@@ -127,6 +123,7 @@ func Setup() {
|
||||
j.CronExpression = jobList[i].CronExpression
|
||||
j.JobId = jobList[i].JobId
|
||||
j.Name = jobList[i].JobName
|
||||
j.JobGroup = jobList[i].JobGroup
|
||||
j.MisfirePolicy = jobList[i].MisfirePolicy
|
||||
sysJob.EntryId, err = AddJob(Crontab, j)
|
||||
} else if jobList[i].JobType == "2" {
|
||||
@@ -135,6 +132,7 @@ func Setup() {
|
||||
j.CronExpression = jobList[i].CronExpression
|
||||
j.JobId = jobList[i].JobId
|
||||
j.Name = jobList[i].JobName
|
||||
j.JobGroup = jobList[i].JobGroup
|
||||
j.Args = jobList[i].Args
|
||||
j.MisfirePolicy = jobList[i].MisfirePolicy
|
||||
sysJob.EntryId, err = AddJob(Crontab, j)
|
||||
|
||||
Reference in New Issue
Block a user