-
Notifications
You must be signed in to change notification settings - Fork 24
/
datastore.go
40 lines (37 loc) · 1.1 KB
/
datastore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package engine
import (
"github.com/pkg/errors"
"github.com/runabol/tork/conf"
"github.com/runabol/tork/datastore"
"github.com/runabol/tork/datastore/inmemory"
"github.com/runabol/tork/datastore/postgres"
)
func (e *Engine) initDatastore() error {
dstype := conf.StringDefault("datastore.type", datastore.DATASTORE_INMEMORY)
ds, err := e.createDatastore(dstype)
if err != nil {
return err
}
e.ds = ds
return nil
}
func (e *Engine) createDatastore(dstype string) (datastore.Datastore, error) {
dsp, ok := e.dsProviders[dstype]
if ok {
return dsp()
}
switch dstype {
case datastore.DATASTORE_INMEMORY:
return inmemory.NewInMemoryDatastore(), nil
case datastore.DATASTORE_POSTGRES:
dsn := conf.StringDefault(
"datastore.postgres.dsn",
"host=localhost user=tork password=tork dbname=tork port=5432 sslmode=disable",
)
return postgres.NewPostgresDataStore(dsn,
postgres.WithTaskLogRetentionPeriod(conf.DurationDefault("datastore.postgres.task.logs.interval", postgres.DefaultTaskLogsRetentionPeriod)),
)
default:
return nil, errors.Errorf("unknown datastore type: %s", dstype)
}
}