File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
websites/code/studygolang/src/server/indexer Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"math/rand"
11
11
"runtime"
12
12
"time"
13
+ "flag"
13
14
//"path/filepath"
14
15
15
16
"github.com/robfig/cron"
@@ -25,26 +26,37 @@ func init() {
25
26
}
26
27
27
28
func main () {
29
+ var manualIndex bool
30
+ flag .BoolVar (& manualIndex , "manual" , false , "do manual index once or not" )
31
+ flag .Parse ()
32
+
33
+ if manualIndex {
34
+ indexing (true )
35
+ }
28
36
29
37
c := cron .New ()
30
38
// 构建 solr 需要的索引数据
31
39
// 一天一次全量
32
40
c .AddFunc ("@daily" , func () {
33
- logger .Infoln ("indexing start..." )
34
-
35
- start := time .Now ()
36
- defer func () {
37
- logger .Infoln ("indexing spend time:" , time .Now ().Sub (start ))
38
- }()
39
-
40
- service .Indexing (true )
41
+ indexing (true )
41
42
})
42
43
43
44
c .Start ()
44
45
45
46
select {}
46
47
}
47
48
49
+ func indexing (isAll bool ) {
50
+ logger .Infoln ("indexing start..." )
51
+
52
+ start := time .Now ()
53
+ defer func () {
54
+ logger .Infoln ("indexing spend time:" , time .Now ().Sub (start ))
55
+ }()
56
+
57
+ service .Indexing (isAll )
58
+ }
59
+
48
60
// 保存PID
49
61
func SavePid () {
50
62
/*
You can’t perform that action at this time.
0 commit comments