Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Commit

Permalink
Tasks should be a map of pointer otherwise I'm not able to get the go…
Browse files Browse the repository at this point in the history
…od values
  • Loading branch information
owulveryck committed Dec 13, 2015
1 parent 0f984f0 commit 1b4c712
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions executor/example/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": 0,
"name": "a",
"engine": "sleep",
"artifact": "example/script.sh",
"args": null,
"output": null
}

4 changes: 2 additions & 2 deletions executor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion executor/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions executor/webhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b4c712

Please sign in to comment.