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