Skip to content

Commit

Permalink
Use boltdb as default storage
Browse files Browse the repository at this point in the history
This will provide a quick start for anyone wanting to try Dkron without clustering, making it running in single node super easy.
  • Loading branch information
Victor Castell committed Nov 22, 2018
1 parent 53d8464 commit 3fdba5f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ main
*.log
config/
dist
dkron.db
39 changes: 24 additions & 15 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/abronan/leadership"
"github.com/abronan/valkeyrie/store"
metrics "github.com/armon/go-metrics"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/serf/serf"
Expand Down Expand Up @@ -292,7 +293,11 @@ func (a *Agent) SetConfig(c *Config) {

func (a *Agent) StartServer() {
if a.Store == nil {
a.Store = NewStore(a.config.Backend, a.config.BackendMachines, a, a.config.Keyspace, nil)
var sConfig *store.Config
if a.config.Backend == "boltdb" {
sConfig = &store.Config{Bucket: a.config.Keyspace}
}
a.Store = NewStore(a.config.Backend, a.config.BackendMachines, a, a.config.Keyspace, sConfig)
if err := a.Store.Healthy(); err != nil {
log.WithError(err).Fatal("store: Store backend not reachable")
}
Expand All @@ -312,7 +317,11 @@ func (a *Agent) StartServer() {
log.WithError(err).Fatal("agent: RPC server failed to start")
}

a.participate()
if a.config.Backend != "boltdb" {
a.participate()
} else {
a.schedule()
}
}

func (a *Agent) participate() {
Expand Down Expand Up @@ -625,23 +634,23 @@ func (a *Agent) RefreshJobStatus(jobName string) {

// If there is pending executions to finish ask if they are really pending.
if len(nodes) > 0 && group != "" {
statuses := a.executionDoneQuery(nodes, group)
statuses := a.executionDoneQuery(nodes, group)

log.WithFields(logrus.Fields{
"statuses": statuses,
}).Debug("agent: Received pending executions response")

for _, ex := range unfinishedExecutions {
if s, ok := statuses[ex.NodeName]; ok {
done, _ := strconv.ParseBool(s)
if done {
log.WithFields(logrus.Fields{
"statuses": statuses,
}).Debug("agent: Received pending executions response")

for _, ex := range unfinishedExecutions {
if s, ok := statuses[ex.NodeName]; ok {
done, _ := strconv.ParseBool(s)
if done {
ex.FinishedAt = time.Now()
a.Store.SetExecution(ex)
}
} else {
ex.FinishedAt = time.Now()
a.Store.SetExecution(ex)
}
} else {
ex.FinishedAt = time.Now()
a.Store.SetExecution(ex)
}
}
}
}
4 changes: 2 additions & 2 deletions dkron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func DefaultConfig() *Config {
NodeName: hostname,
BindAddr: fmt.Sprintf("0.0.0.0:%d", DefaultBindPort),
HTTPAddr: ":8080",
Backend: "etcdv3",
BackendMachines: []string{"127.0.0.1:2379"},
Backend: "boltdb",
BackendMachines: []string{"./dkron.db"},
Profile: "lan",
Keyspace: "dkron",
LogLevel: "info",
Expand Down
2 changes: 2 additions & 0 deletions dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/abronan/valkeyrie"
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/boltdb"
"github.com/abronan/valkeyrie/store/consul"
"github.com/abronan/valkeyrie/store/etcd/v2"
"github.com/abronan/valkeyrie/store/etcd/v3"
Expand Down Expand Up @@ -55,6 +56,7 @@ func init() {
consul.Register()
zookeeper.Register()
redis.Register()
boltdb.Register()
}

func NewStore(backend string, machines []string, a *Agent, keyspace string, config *store.Config) *Store {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/abronan/valkeyrie v0.0.0-20171113095143-063d875e3c5f
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6
github.com/coreos/bbolt v1.3.0 // indirect
github.com/coreos/etcd v3.2.9+incompatible // indirect
github.com/coreos/go-semver v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.2 // indirect
github.com/gin-contrib/multitemplate v0.0.0-20170922032617-bbc6daf6024b
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6 h1:rfTl4Lc+Gfud1YdmAFg99WN4rICM1S65KXBuADdLTms=
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.2.9+incompatible h1:rK6tzefpypqZLvs9aX7R5vcl4u1xucf2esUzFvJM6vw=
github.com/coreos/etcd v3.2.9+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY=
Expand Down

0 comments on commit 3fdba5f

Please sign in to comment.