diff --git a/models/task_log.go b/models/task_log.go index f28be96..6ca8e99 100644 --- a/models/task_log.go +++ b/models/task_log.go @@ -6,17 +6,11 @@ import ( type TaskType int8 -const ( - Timing = iota + 1 // 定时任务 - Delay // 延时任务 -) // 任务执行日志 type TaskLog struct { Id int64 `xorm:"bigint pk autoincr"` TaskId int `xorm:"int notnull index default 0"` // 任务id - Type TaskType `xorm:"tinyint notnull default 1"` // 任务类型 1 定时任务 2 延时任务 - Delay int `xorm:"int notnull default 0"` // 延时任务-延时时间 Name string `xorm:"varchar(64) notnull"` // 任务名称 Spec string `xorm:"varchar(64) notnull"` // crontab Protocol TaskProtocol `xorm:"tinyint notnull"` // 协议 1:http 2:ssh-command @@ -25,7 +19,7 @@ type TaskLog struct { Hostname string `xorm:"varchar(512) notnull defalut '' "` // SSH主机名,逗号分隔 StartTime time.Time `xorm:"datetime created"` // 开始执行时间 EndTime time.Time `xorm:"datetime updated"` // 执行完成(失败)时间 - Status Status `xorm:"tinyint notnull default 1"` // 状态 1:执行中 2:执行完毕 0:执行失败 -1 待执行 + Status Status `xorm:"tinyint notnull default 1"` // 状态 1:执行中 2:执行完毕 0:执行失败 Result string `xorm:"varchar(65535) notnull defalut '' "` // 执行结果 Page int `xorm:"-"` PageSize int `xorm:"-"` diff --git a/modules/logger/logger.go b/modules/logger/logger.go index 3af4fe2..ef4c531 100644 --- a/modules/logger/logger.go +++ b/modules/logger/logger.go @@ -93,16 +93,16 @@ func writef(level Level, format string, v... interface{}) { switch level { case DEBUG: - logger.Debugf(v) + logger.Debugf(format, v) case INFO: - logger.Infof(v) + logger.Infof(format, v) case WARN: - logger.Warnf(v) + logger.Warnf(format, v) case FATAL: - logger.Criticalf(v) + logger.Criticalf(format, v) os.Exit(1) case ERROR: - logger.Errorf(v) + logger.Errorf(format, v) } } diff --git a/routers/api/v1/delaytask/delay_task.go b/routers/api/v1/delaytask/delay_task.go deleted file mode 100644 index b9362ae..0000000 --- a/routers/api/v1/delaytask/delay_task.go +++ /dev/null @@ -1,20 +0,0 @@ -package delaytask - -import ( - "gopkg.in/macaron.v1" - "github.com/ouqiang/gocron/models" -) - -type DelayForm struct { - Protocol models.TaskType - Type models.TaskType - Host string - Delay int - Command string - Timeout int -} - -// 创建延时任务 -func Create(ctx *macaron.Context) { - -} \ No newline at end of file diff --git a/routers/routers.go b/routers/routers.go index 844770f..6adaf1a 100644 --- a/routers/routers.go +++ b/routers/routers.go @@ -14,7 +14,6 @@ import ( "github.com/go-macaron/gzip" "strings" "github.com/ouqiang/gocron/modules/app" - "github.com/ouqiang/gocron/routers/api/v1/delaytask" ) // 静态文件目录 @@ -76,12 +75,6 @@ func Register(m *macaron.Macaron) { m.Get("", host.Index) m.Post("/remove/:id", host.Remove) }) - - // API接口 - m.Group("/api/v1", func() { - // 添加延时任务 - m.Post("/task/delay", delaytask.Create) - }) } // 中间件注册 diff --git a/service/task.go b/service/task.go index 67cb427..e85c6f2 100644 --- a/service/task.go +++ b/service/task.go @@ -106,7 +106,6 @@ func (h *SSHCommandHandler) Run(taskModel models.TaskHost) (string, error) { func createTaskLog(taskModel models.TaskHost) (int64, error) { taskLogModel := new(models.TaskLog) taskLogModel.TaskId = taskModel.Id - taskLogModel.Type = models.Timing taskLogModel.Name = taskModel.Task.Name taskLogModel.Spec = taskModel.Spec taskLogModel.Protocol = taskModel.Protocol diff --git a/templates/task/log.html b/templates/task/log.html index f29edb4..73fcfd8 100644 --- a/templates/task/log.html +++ b/templates/task/log.html @@ -27,11 +27,9 @@ 任务名称 - 任务类型 cron表达式 协议 超时时间(秒) - 延时时间(秒) 主机 开始时间 结束时间 @@ -43,17 +41,15 @@ {{{range $i, $v := .Logs}}} {{{.Name}}} - {{{if eq .Type 1}}}定时任务{{{else}}}延时任务{{{end}}} {{{.Spec}}} {{{if eq .Protocol 1}}} HTTP {{{else}}} SSH {{{end}}} {{{.Timeout}}} - {{{.Delay}}} {{{.Hostname}}} - {{{.StartTime.Format "2006-01-02 15:03:04" }}} + {{{.StartTime.Format "2006-01-02 15:04:05" }}} - {{{.EndTime.Format "2006-01-02 15:03:04" }}} + {{{.EndTime.Format "2006-01-02 15:04:05" }}} {{{if eq .Status 2}}}