Skip to content

Commit

Permalink
Merge pull request #136 from keis/list-tasks-empty-db
Browse files Browse the repository at this point in the history
List tasks empty db
  • Loading branch information
keis authored Sep 13, 2016
2 parents a11537f + 0de4439 commit 3b98ec7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
17 changes: 8 additions & 9 deletions boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package boltdb
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

Expand All @@ -29,10 +28,6 @@ type connector interface {
type defaultConnector struct{}

func (b defaultConnector) Open(file string) (connection, error) {
if !filepath.IsAbs(file) {
dir, _ := os.Getwd()
file = fmt.Sprintf("%s/../%s", dir, file)
}
os.MkdirAll(filepath.Dir(file), 0755)

return bolt.Open(file, 0600, nil)
Expand All @@ -57,6 +52,14 @@ func newCustomTaskDB(c connector, file string) (*TaskDB, error) {
return nil, err
}

err = conn.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte("tasks"))
return err
})
if err != nil {
return nil, err
}

return &TaskDB{conn: conn}, nil
}

Expand All @@ -74,10 +77,6 @@ func (db *TaskDB) Clean() error {
return err
}

if _, err := tx.CreateBucketIfNotExists([]byte("tasks")); err != nil {
return err
}

return nil
})
}
Expand Down
Empty file removed db/.keep
Empty file.
2 changes: 0 additions & 2 deletions misc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ paths:
description: Task details
schema:
$ref: '#/definitions/Task'
404:
description: No tasks found
default:
description: Unexpected error
post:
Expand Down
1 change: 1 addition & 0 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (h Handler) ListRunningTasks() http.HandlerFunc {
tasks, err := h.database.ListNonTerminalTasks()
if err != nil {
handleError(err, w, "Unable to fetch running tasks from the database")
return
}
writeJSON(200, tasks, w)
}
Expand Down

0 comments on commit 3b98ec7

Please sign in to comment.