fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

cmd/zoekt-indexserver: set timeout on zoekt-git-index calls

Change-Id: I17c84126feb46deec68e5cea08c11c146253cba4

+21 -11
+21 -11
cmd/zoekt-indexserver/main.go
··· 21 21 22 22 import ( 23 23 "bytes" 24 + "context" 24 25 "flag" 25 26 "fmt" 26 27 "log" ··· 62 63 indexFlags []string 63 64 mirrorConfigFile string 64 65 maxLogAge time.Duration 66 + indexTimeout time.Duration 65 67 } 66 68 67 69 func (o *Options) validate() { ··· 79 81 } 80 82 81 83 func (o *Options) defineFlags() { 84 + flag.DurationVar(&o.indexTimeout, "index_timeout", time.Hour, "kill index job after this much time") 82 85 flag.DurationVar(&o.maxLogAge, "max_log_age", 3*day, "recycle index logs after this much time") 83 86 flag.DurationVar(&o.fetchInterval, "fetch_interval", time.Hour, "run fetches this often") 84 87 flag.StringVar(&o.mirrorConfigFile, "mirror_config", ··· 147 150 // indexes them, sequentially. 148 151 func indexPendingRepos(indexDir, repoDir string, opts *Options, repos <-chan string) { 149 152 for dir := range repos { 150 - args := []string{ 151 - "-require_ctags", 152 - fmt.Sprintf("-parallelism=%d", opts.cpuCount), 153 - "-repo_cache", repoDir, 154 - "-index", indexDir, 155 - "-incremental", 156 - } 157 - args = append(args, opts.indexFlags...) 158 - args = append(args, dir) 159 - cmd := exec.Command("zoekt-git-index", args...) 160 - loggedRun(cmd) 153 + indexPendingRepo(dir, indexDir, repoDir, opts) 161 154 } 155 + } 156 + 157 + func indexPendingRepo(dir, indexDir, repoDir string, opts *Options) { 158 + ctx, cancel := context.WithTimeout(context.Background(), opts.indexTimeout) 159 + defer cancel() 160 + args := []string{ 161 + "-require_ctags", 162 + fmt.Sprintf("-parallelism=%d", opts.cpuCount), 163 + "-repo_cache", repoDir, 164 + "-index", indexDir, 165 + "-incremental", 166 + } 167 + args = append(args, opts.indexFlags...) 168 + args = append(args, dir) 169 + cmd := exec.CommandContext(ctx, "zoekt-git-index", args...) 170 + loggedRun(cmd) 171 + 162 172 } 163 173 164 174 // deleteLogs deletes old logs.