Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuntDB with delete executions and fixed tests #702

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dkron/agent.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading