- remove tasksch.TaskMan.Run*** funcs
This commit is contained in:
@@ -18,18 +18,6 @@ func init() {
|
||||
defTaskMan.taskList = make(map[string]ITask)
|
||||
}
|
||||
|
||||
func (m *TaskMan) RunParallelTask(taskName string, config *ParallelConfig, userName string, worker WorkFunc, itemList interface{}, params ...interface{}) *ParallelTask {
|
||||
task := RunParallelTask(taskName, config, userName, worker, itemList, params...)
|
||||
m.ManageTask(task)
|
||||
return task
|
||||
}
|
||||
|
||||
func (m *TaskMan) RunSeqTask(taskName string, userName string, worker SeqWorkFunc, stepCount int, params ...interface{}) *SeqTask {
|
||||
task := RunSeqTask(taskName, userName, worker, stepCount, params...)
|
||||
m.ManageTask(task)
|
||||
return task
|
||||
}
|
||||
|
||||
func (m *TaskMan) GetTasks(taskID string, fromStatus, toStatus int, lastHours int) (taskList TaskList) {
|
||||
if lastHours == 0 {
|
||||
lastHours = defLastHours
|
||||
@@ -50,14 +38,6 @@ func (m *TaskMan) ManageTask(task ITask) ITask {
|
||||
return task
|
||||
}
|
||||
|
||||
func RunManagedParallelTask(taskName string, config *ParallelConfig, userName string, worker WorkFunc, itemList interface{}, params ...interface{}) *ParallelTask {
|
||||
return defTaskMan.RunParallelTask(taskName, config, userName, worker, itemList, params...)
|
||||
}
|
||||
|
||||
func RunManagedSeqTask(taskName string, userName string, worker SeqWorkFunc, stepCount int, params ...interface{}) *SeqTask {
|
||||
return defTaskMan.RunSeqTask(taskName, userName, worker, stepCount, params...)
|
||||
}
|
||||
|
||||
func GetTasks(taskID string, fromStatus, toStatus int, lastHours int) (taskList TaskList) {
|
||||
return defTaskMan.GetTasks(taskID, fromStatus, toStatus, lastHours)
|
||||
}
|
||||
|
||||
@@ -1,51 +1,9 @@
|
||||
package tasksch
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestTaskMan(t *testing.T) {
|
||||
itemList := make([]int, 100)
|
||||
for k := range itemList {
|
||||
itemList[k] = k
|
||||
}
|
||||
config1 := NewParallelConfig().SetResultHandler(func(taskName string, result []interface{}, err error) {
|
||||
// t.Log("finished here")
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}).SetParallelCount(100).SetBatchSize(7)
|
||||
task1 := RunManagedParallelTask("test", config1, "autotest", func(task *ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
sleepSecond := rand.Intn(5)
|
||||
t.Logf("sleep %d seconds", sleepSecond)
|
||||
time.Sleep(time.Duration(sleepSecond) * time.Second)
|
||||
retSlice := make([]string, len(batchItemList))
|
||||
for k := range retSlice {
|
||||
retSlice[k] = "hello:" + utils.Int2Str(batchItemList[k].(int)*2)
|
||||
}
|
||||
return retSlice, nil
|
||||
}, itemList, "a", "b", 1, 2)
|
||||
|
||||
config2 := NewParallelConfig().SetResultHandler(func(taskName string, result []interface{}, err error) {
|
||||
// t.Log("finished here")
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}).SetParallelCount(100).SetBatchSize(7)
|
||||
task2 := RunManagedParallelTask("test", config2, "autotest", func(task *ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
sleepSecond := rand.Intn(5)
|
||||
t.Logf("sleep %d seconds", sleepSecond)
|
||||
time.Sleep(time.Duration(sleepSecond) * time.Second)
|
||||
retSlice := make([]string, len(batchItemList))
|
||||
for k := range retSlice {
|
||||
retSlice[k] = "hello:" + utils.Int2Str(batchItemList[k].(int)*2)
|
||||
}
|
||||
return retSlice, nil
|
||||
}, itemList, "a", "b", 1, 2)
|
||||
time.Sleep(2 * time.Second)
|
||||
task2.Cancel()
|
||||
if task1.GetStatus() == task2.GetStatus() {
|
||||
t.Log(utils.Format4Output(GetTasks("", TaskStatusBegin, TaskStatusEnd, 5), false))
|
||||
t.Fatal("status should not be same")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user