From a5a30391afd7927f27664d9c655bd43f82b8d241 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 21 Apr 2020 18:05:11 +0800 Subject: [PATCH] =?UTF-8?q?TODO:=20=E6=8C=81=E4=B9=85=E5=8C=96=E6=88=98?= =?UTF-8?q?=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hunter.go | 23 +++++++++++++++++++++++ hunter_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/hunter.go b/hunter.go index 7d7bd0e..816b662 100644 --- a/hunter.go +++ b/hunter.go @@ -95,9 +95,15 @@ func (hunter *Hunter) SetShare(key string, value interface{}) { // Execute 执行任务 func (hunter *Hunter) Execute() { + + if hunter.executes.Size() != 0 { + hunter.recursionTasks() + } + for _, task := range hunter.tasks { hunter.execute(task) } + } // Execute 执行任务 @@ -187,6 +193,23 @@ func (hunter *Hunter) AddTask(task ITask) { hunter.tasks = append(hunter.tasks, task) } +// SavePoint 持续 +func (hunter *Hunter) savePoint() { + // f, err := os.OpenFile("./gob.log", os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm) + // if err != nil { + // panic(err) + // } + // enc := gob.NewEncoder(f) + // err = enc.Encode(hunter.executes.Values()) + // if err != nil { + // panic(err) + // } + // for _, iv := range hunter.executes.Values() { + // tc := iv.(*TaskContext) + + // } +} + // Execute 执行 // func (hunter *Hunter) Execute() { // if itask, ok := hunter.task.Children().Top(); ok { diff --git a/hunter_test.go b/hunter_test.go index 6321928..93b0ee3 100644 --- a/hunter_test.go +++ b/hunter_test.go @@ -99,3 +99,48 @@ func TestCaseWebSub(t *testing.T) { } } + +type WebSavePoint struct { + PrePostUrl +} + +func (web *WebSavePoint) Execute(cxt *TaskContext) { + wf := cxt.Workflow() + wf.SetBodyAuto(`{"a": "1","url":["http://httpbin.org/post","http://httpbin.org/get"]}`) + resp, err := wf.Execute() + if err != nil { + panic(err) + } + cxt.SetShare("test", resp.Content()) + + data := make(map[string]interface{}) + json.Unmarshal(resp.Content(), &data) + if urlList, ok := data["json"].(map[string]interface{})["url"].([]interface{}); ok { + for _, is := range urlList { + s := is.(string) + cxt.AddTask(&WebSavePoint1{PrePostUrl(s)}) + } + } +} + +type WebSavePoint1 struct { + PrePostUrl +} + +func (web *WebSavePoint1) Execute(cxt *TaskContext) { + cxt.SetShare("test", cxt.Path()+"/"+cxt.TaskID()) + cxt.hunter.savePoint() +} + +func TestSavePoint(t *testing.T) { + + hunter := NewHunter() + hunter.AddTask(&WebSavePoint{"http://httpbin.org/post"}) + hunter.Execute() + + content := hunter.GetShare("test").(string) + if content != "/0/1" { + t.Error(content) + } + +}