From 1b4c71289b60731db5025345ffea0fa4c33fedda Mon Sep 17 00:00:00 2001 From: Olivier Wulveryck Date: Sun, 13 Dec 2015 10:21:26 +0100 Subject: [PATCH] Tasks should be a map of pointer otherwise I'm not able to get the good values --- executor/example/example.json | 9 +++++++++ executor/main.go | 4 ++-- executor/node.go | 1 - executor/webhandler.go | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 executor/example/example.json diff --git a/executor/example/example.json b/executor/example/example.json new file mode 100644 index 0000000..9248747 --- /dev/null +++ b/executor/example/example.json @@ -0,0 +1,9 @@ + { + "id": 0, + "name": "a", + "engine": "sleep", + "artifact": "example/script.sh", + "args": null, + "output": null + } + diff --git a/executor/main.go b/executor/main.go index d12833b..cf9d06b 100644 --- a/executor/main.go +++ b/executor/main.go @@ -44,11 +44,11 @@ func uuid() Task { } // This will hold all the requested tasks -var tasks map[string]node +var tasks map[string](*node) func Run() { - tasks = make(map[string]node, 0) + tasks = make(map[string](*node), 0) router := NewRouter() log.Fatal(http.ListenAndServe(":8585", router)) diff --git a/executor/node.go b/executor/node.go index d600628..fde3ba6 100644 --- a/executor/node.go +++ b/executor/node.go @@ -11,5 +11,4 @@ type node orchestrator.Node func (n *node) Run() { log.Printf("Running %v with engine %v, artifact %v and args %v", n.Name, n.Engine, n.Artifact, n.Args) n.State = orchestrator.Success - log.Println(n.State) } diff --git a/executor/webhandler.go b/executor/webhandler.go index c1842f8..15432eb 100644 --- a/executor/webhandler.go +++ b/executor/webhandler.go @@ -39,7 +39,7 @@ func TaskShow(w http.ResponseWriter, r *http.Request) { if v, ok := tasks[id]; ok { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) - if err := json.NewEncoder(w).Encode(v); err != nil { + if err := json.NewEncoder(w).Encode(*v); err != nil { panic(err) } return @@ -79,7 +79,7 @@ func TaskCreate(w http.ResponseWriter, r *http.Request) { uuid := uuid() go v.Run() - tasks[uuid.ID] = v + tasks[uuid.ID] = &v w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusAccepted)