Browse Source

:art: 后台任务显示当前正在执行的任务

Liang Ding 2 năm trước cách đây
mục cha
commit
9a7a155ac7
1 tập tin đã thay đổi với 9 bổ sung0 xóa
  1. 9 0
      kernel/task/queue.go

+ 9 - 0
kernel/task/queue.go

@@ -121,6 +121,11 @@ func StatusJob() {
 		item := map[string]interface{}{"action": action}
 		item := map[string]interface{}{"action": action}
 		items = append(items, item)
 		items = append(items, item)
 	}
 	}
+
+	if "" != currentTaskAction {
+		items = append([]map[string]interface{}{map[string]interface{}{"action": currentTaskAction}}, items...)
+	}
+
 	if 1 > len(items) {
 	if 1 > len(items) {
 		items = []map[string]interface{}{}
 		items = []map[string]interface{}{}
 	}
 	}
@@ -141,6 +146,8 @@ func ExecTaskJob() {
 	execTask(task)
 	execTask(task)
 }
 }
 
 
+var currentTaskAction string
+
 func popTask() (ret *Task) {
 func popTask() (ret *Task) {
 	queueLock.Lock()
 	queueLock.Lock()
 	defer queueLock.Unlock()
 	defer queueLock.Unlock()
@@ -166,6 +173,8 @@ func execTask(task *Task) {
 		}
 		}
 	}
 	}
 
 
+	currentTaskAction = task.Action
+
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
 	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
 	defer cancel()
 	defer cancel()
 	ch := make(chan bool, 1)
 	ch := make(chan bool, 1)