forked from zph/moresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoresql.go
59 lines (46 loc) · 1.2 KB
/
moresql.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package moresql
import (
"flag"
"net/http"
"sync"
"time"
log "github.com/Sirupsen/logrus"
)
// workerCount dedicated workers per collection
const workerCount = 5
// workerCountOverflow Threads in Golang 1.6+ are ~4kb to start
// 500 * 4k = ~2MB ram usage due to heap of each routine
const workerCountOverflow = 500
// reportFrequency the timing for how often to report activity
const reportFrequency = 60 // seconds
// checkpointFrequency frequency at which checkpointing is saved to DB
const checkpointFrequency = time.Duration(30) * time.Second
var wg sync.WaitGroup
func Run() {
c := Commands{}
env := FetchEnvsAndFlags()
SetupLogger(env)
ExitUnlessValidEnv(env)
config := LoadConfig(env.configFile)
pg := GetPostgresConnection(env)
defer pg.Close()
// TODO: should this run for each execution of application
if env.validatePostgres {
c.ValidateTablesAndColumns(config, pg)
}
session := GetMongoConnection(env)
defer session.Close()
log.Info("Connected to postgres")
log.Info("Connected to mongo")
if env.monitor {
go http.ListenAndServe(":1234", nil)
}
switch {
case env.sync:
FullSync(config, pg, session)
case env.tail:
Tail(config, pg, session, env)
default:
flag.Usage()
}
}