godoc: add IndexInterval option

This will permit deleting some forked code elsewhere.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/22010046
This commit is contained in:
Brad Fitzpatrick 2013-11-06 13:31:30 -05:00
parent 0b5928ea2a
commit 42513df8b8
2 changed files with 14 additions and 5 deletions

View File

@ -39,6 +39,12 @@ type Corpus struct {
// zero value for IndexThrottle means 0.9. // zero value for IndexThrottle means 0.9.
IndexThrottle float64 IndexThrottle float64
// IndexInterval specifies the time to sleep between reindexing
// all the sources.
// If zero, a default is used. If negative, the index is only
// built once.
IndexInterval time.Duration
// MaxResults optionally specifies the maximum results for indexing. // MaxResults optionally specifies the maximum results for indexing.
// The default is 1000. // The default is 1000.
MaxResults int MaxResults int

View File

@ -1167,7 +1167,8 @@ func (c *Corpus) RunIndexer() {
// initialize the index from disk if possible // initialize the index from disk if possible
if c.IndexFiles != "" { if c.IndexFiles != "" {
if err := c.readIndex(c.IndexFiles); err != nil { if err := c.readIndex(c.IndexFiles); err != nil {
log.Printf("error reading index: %s", err) log.Printf("error reading index from file %s: %v", c.IndexFiles, err)
return
} }
} }
@ -1177,10 +1178,12 @@ func (c *Corpus) RunIndexer() {
// index possibly out of date - make a new one // index possibly out of date - make a new one
c.UpdateIndex() c.UpdateIndex()
} }
delay := 60 * time.Second // by default, try every 60s if c.IndexInterval < 0 {
if false { // TODO(bradfitz): was: *testDir != "" { return
// in test mode, try once a second for fast startup }
delay = 1 * time.Second delay := 5 * time.Minute // by default, reindex every 5 minutes
if c.IndexInterval > 0 {
delay = c.IndexInterval
} }
time.Sleep(delay) time.Sleep(delay)
} }