Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc00529

Browse files
author
xuxinhua
committed
增加手动建索引功能
1 parent 5742f62 commit cc00529

File tree

1 file changed

+20
-8
lines changed
  • websites/code/studygolang/src/server/indexer

1 file changed

+20
-8
lines changed

websites/code/studygolang/src/server/indexer/main.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"math/rand"
1111
"runtime"
1212
"time"
13+
"flag"
1314
//"path/filepath"
1415

1516
"github.com/robfig/cron"
@@ -25,26 +26,37 @@ func init() {
2526
}
2627

2728
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+
}
2836

2937
c := cron.New()
3038
// 构建 solr 需要的索引数据
3139
// 一天一次全量
3240
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)
4142
})
4243

4344
c.Start()
4445

4546
select {}
4647
}
4748

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+
4860
// 保存PID
4961
func SavePid() {
5062
/*

0 commit comments

Comments
 (0)