-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_config.go
More file actions
47 lines (43 loc) · 1.11 KB
/
database_config.go
File metadata and controls
47 lines (43 loc) · 1.11 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
package queue
import (
"database/sql"
"time"
)
const (
defaultProcessingRecoveryGrace = 2 * time.Second
defaultProcessingLeaseNoTimeout = 5 * time.Minute
)
// DatabaseConfig configures the SQL-backed database q.
// @group Config
type DatabaseConfig struct {
DB *sql.DB
DriverName string
DSN string
Workers int
PollInterval time.Duration
DefaultQueue string
AutoMigrate bool
ProcessingRecoveryGrace time.Duration
ProcessingLeaseNoTimeout time.Duration
Observer Observer
Logger Logger
}
func (c DatabaseConfig) normalize() DatabaseConfig {
c.Workers = defaultWorkerCount(c.Workers)
if c.PollInterval <= 0 {
c.PollInterval = 50 * time.Millisecond
}
if c.DefaultQueue == "" {
c.DefaultQueue = "default"
}
if !c.AutoMigrate {
c.AutoMigrate = true
}
if c.ProcessingRecoveryGrace <= 0 {
c.ProcessingRecoveryGrace = defaultProcessingRecoveryGrace
}
if c.ProcessingLeaseNoTimeout <= 0 {
c.ProcessingLeaseNoTimeout = defaultProcessingLeaseNoTimeout
}
return c
}