Skip to content

Commit

Permalink
BuntDB with delete executions and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Golev committed Mar 11, 2020
1 parent 007912d commit b55a5f7
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 327 deletions.
4 changes: 2 additions & 2 deletions dkron/agent.go
Expand Up @@ -276,7 +276,7 @@ func (a *Agent) setupRaft() error {
// Create the BoltDB backend
s, err := raftboltdb.NewBoltStore(filepath.Join(a.config.DataDir, "raft", "raft.db"))
if err != nil {
return fmt.Errorf("error creating new badger store: %s", err)
return fmt.Errorf("error creating new raft store: %s", err)
}
a.raftStore = s
stableStore = s
Expand Down Expand Up @@ -455,7 +455,7 @@ func (a *Agent) StartServer() {
}

if a.Store == nil {
s, err := NewStore(filepath.Join(a.config.DataDir, a.config.NodeName))
s, err := NewStore(a)
if err != nil {
log.WithError(err).Fatal("dkron: Error initializing store")
}
Expand Down
4 changes: 2 additions & 2 deletions dkron/api.go
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"net/http"

"github.com/dgraph-io/badger/v2"
"github.com/gin-contrib/expvar"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/tidwall/buntdb"
status "google.golang.org/grpc/status"
)

Expand Down Expand Up @@ -224,7 +224,7 @@ func (h *HTTPTransport) executionsHandler(c *gin.Context) {

executions, err := h.agent.Store.GetExecutions(job.Name)
if err != nil {
if err == badger.ErrKeyNotFound {
if err == buntdb.ErrNotFound {
renderJSON(c, http.StatusOK, &[]Execution{})
return
}
Expand Down
4 changes: 2 additions & 2 deletions dkron/job.go
Expand Up @@ -6,13 +6,13 @@ import (
"regexp"
"time"

"github.com/dgraph-io/badger/v2"
"github.com/distribworks/dkron/v2/extcron"
"github.com/distribworks/dkron/v2/ntime"
"github.com/distribworks/dkron/v2/plugin"
proto "github.com/distribworks/dkron/v2/plugin/types"
"github.com/golang/protobuf/ptypes"
"github.com/sirupsen/logrus"
"github.com/tidwall/buntdb"
)

const (
Expand Down Expand Up @@ -297,7 +297,7 @@ func (j *Job) GetParent(store *Store) (*Job, error) {

parentJob, err := store.GetJob(j.ParentJob, nil)
if err != nil {
if err == badger.ErrKeyNotFound {
if err == buntdb.ErrNotFound {
return nil, ErrParentJobNotFound
}
return nil, err
Expand Down
14 changes: 2 additions & 12 deletions dkron/job_test.go
@@ -1,8 +1,6 @@
package dkron

import (
"io/ioutil"
"os"
"testing"

"github.com/distribworks/dkron/v2/plugin"
Expand All @@ -12,11 +10,7 @@ import (
)

func TestJobGetParent(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

s, err := NewStore(dir)
s, err := NewStore(nil)
defer s.Shutdown()
require.NoError(t, err)

Expand Down Expand Up @@ -105,11 +99,7 @@ func TestToProto(t *testing.T) {
}

func Test_isRunnable(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

s, err := NewStore(dir)
s, err := NewStore(nil)
a := &Agent{
Store: s,
}
Expand Down
4 changes: 2 additions & 2 deletions dkron/queries_test.go
Expand Up @@ -7,10 +7,10 @@ import (
"testing"
"time"

"github.com/dgraph-io/badger/v2"
"github.com/hashicorp/serf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/buntdb"
)

func TestRunQuery(t *testing.T) {
Expand All @@ -37,7 +37,7 @@ func TestRunQuery(t *testing.T) {

// Test error with no job
_, err = a.RunQuery("foo", &Execution{})
assert.True(t, errors.Is(err, badger.ErrKeyNotFound))
assert.True(t, errors.Is(err, buntdb.ErrNotFound))

j1 := &Job{
Name: "test_job",
Expand Down
2 changes: 0 additions & 2 deletions dkron/storage.go
Expand Up @@ -10,9 +10,7 @@ type Storage interface {
SetJob(job *Job, copyDependentJobs bool) error
DeleteJob(name string) (*Job, error)
SetExecution(execution *Execution) (string, error)
DeleteExecutions(jobName string) error
SetExecutionDone(execution *Execution) (bool, error)

GetJobs(options *JobOptions) ([]*Job, error)
GetJob(name string, options *JobOptions) (*Job, error)
GetExecutions(jobName string) ([]*Execution, error)
Expand Down

0 comments on commit b55a5f7

Please sign in to comment.