mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 20:10:50 +00:00
commit
19db4b67f6
6
admin.go
6
admin.go
@ -397,7 +397,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
||||
if err != nil {
|
||||
data["Message"] = []string{"error", fmt.Sprintf("%s", err)}
|
||||
}
|
||||
data["Message"] = []string{"success", fmt.Sprintf("%s run success,Now the Status is %s", taskname, t.GetStatus())}
|
||||
data["Message"] = []string{"success", fmt.Sprintf("%s run success,Now the Status is <br>%s", taskname, t.GetStatus())}
|
||||
} else {
|
||||
data["Message"] = []string{"warning", fmt.Sprintf("there's no task which named: %s", taskname)}
|
||||
}
|
||||
@ -410,12 +410,14 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
||||
var fields = []string{
|
||||
fmt.Sprintf("Task Name"),
|
||||
fmt.Sprintf("Task Spec"),
|
||||
fmt.Sprintf("Task Function"),
|
||||
fmt.Sprintf("Task Status"),
|
||||
fmt.Sprintf("Last Time"),
|
||||
fmt.Sprintf(""),
|
||||
}
|
||||
for tname, tk := range toolbox.AdminTaskList {
|
||||
result = []string{
|
||||
fmt.Sprintf("%s", tname),
|
||||
fmt.Sprintf("%s", tk.GetSpec()),
|
||||
fmt.Sprintf("%s", tk.GetStatus()),
|
||||
fmt.Sprintf("%s", tk.GetPrev().String()),
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ bg-warning
|
||||
</td>
|
||||
{{end}}
|
||||
<td>
|
||||
<a class="btn btn-primary btn-sm" href="/task?taskname={{index $slice 1}}">Run</a>
|
||||
<a class="btn btn-primary btn-sm" href="/task?taskname={{index $slice 0}}">Run</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
|
@ -84,6 +84,7 @@ type TaskFunc func() error
|
||||
|
||||
// task interface
|
||||
type Tasker interface {
|
||||
GetSpec() string
|
||||
GetStatus() string
|
||||
Run() error
|
||||
SetNext(time.Time)
|
||||
@ -102,6 +103,7 @@ type taskerr struct {
|
||||
type Task struct {
|
||||
Taskname string
|
||||
Spec *Schedule
|
||||
SpecStr string
|
||||
DoFunc TaskFunc
|
||||
Prev time.Time
|
||||
Next time.Time
|
||||
@ -116,16 +118,22 @@ func NewTask(tname string, spec string, f TaskFunc) *Task {
|
||||
Taskname: tname,
|
||||
DoFunc: f,
|
||||
ErrLimit: 100,
|
||||
SpecStr: spec,
|
||||
}
|
||||
task.SetCron(spec)
|
||||
return task
|
||||
}
|
||||
|
||||
//get spec string
|
||||
func (s *Task) GetSpec() string {
|
||||
return s.SpecStr
|
||||
}
|
||||
|
||||
// get current task status
|
||||
func (tk *Task) GetStatus() string {
|
||||
var str string
|
||||
for _, v := range tk.Errlist {
|
||||
str += v.t.String() + ":" + v.errinfo + "\n"
|
||||
str += v.t.String() + ":" + v.errinfo + "<br>"
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user