This repository was archived by the owner on Jul 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathconfig.go
More file actions
82 lines (73 loc) · 2.22 KB
/
config.go
File metadata and controls
82 lines (73 loc) · 2.22 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cedar
import (
"time"
"github.com/mongodb/amboy"
"github.com/mongodb/amboy/queue"
"github.com/mongodb/grip"
)
// Configuration defines configuration settings to initialize the global
// environment without the presence of a DB to store the settings.
type Configuration struct {
BucketName string
DatabaseName string
QueueName string
MongoDBURI string
DbConfigurationCollection string
MongoDBDialTimeout time.Duration
SocketTimeout time.Duration
DisableLocalQueue bool
DisableRemoteQueue bool
DisableRemoteQueueGroup bool
DisableCache bool
NumWorkers int
DBUser string
DBPwd string
}
// Validate checks that all the required fields are set and sets defaults for
// unset optional fields.
func (c *Configuration) Validate() error {
catcher := grip.NewBasicCatcher()
if c.MongoDBURI == "" {
catcher.New("must specify a MongoDB URI")
}
if c.NumWorkers < 1 {
catcher.New("must specify a valid number of amboy workers")
}
if c.MongoDBDialTimeout <= 0 {
c.MongoDBDialTimeout = 2 * time.Second
}
if c.SocketTimeout <= 0 {
c.SocketTimeout = time.Minute
}
if c.QueueName == "" {
c.QueueName = "cedar.service"
}
return catcher.Resolve()
}
// GetQueueOptions returns the options to initialize a MongoDB-backed Amboy
// queue.
func (c *Configuration) GetQueueOptions() queue.MongoDBOptions {
return queue.MongoDBOptions{
URI: c.MongoDBURI,
DB: c.DatabaseName,
Collection: c.QueueName,
CheckWaitUntil: true,
Format: amboy.BSON2,
WaitInterval: time.Second,
SkipQueueIndexBuilds: true,
SkipReportingIndexBuilds: true,
SampleSize: 300,
}
}
// GetQueueGroupOptions returns the options to initialize a MongoDB-backed Amboy
// queue group.
func (c *Configuration) GetQueueGroupOptions() queue.MongoDBOptions {
opts := c.GetQueueOptions()
opts.UseGroups = true
opts.GroupName = c.QueueName
return opts
}
// HasAuth returns whether or not the DB uses authentication.
func (c *Configuration) HasAuth() bool {
return c.DBUser != ""
}