Retry in case of timeout (#35)
while gradually increasing the time limit
This commit is contained in:
parent
e4671eaf9e
commit
3323163e04
|
@ -84,10 +84,11 @@ before the call.
|
||||||
|
|
||||||
### Options for parallel installer
|
### Options for parallel installer
|
||||||
|
|
||||||
| Flag | Default | Description |
|
| Flag | Default | Description |
|
||||||
| ---------------- | ------- | --------------------------------- |
|
| ---------------- | ------- | ------------------------------------ |
|
||||||
| `g:plug_threads` | 16 | Default number of threads to use |
|
| `g:plug_threads` | 16 | Default number of threads to use |
|
||||||
| `g:plug_timeout` | 60 | Time limit of each task in seconds |
|
| `g:plug_timeout` | 60 | Time limit of each task in seconds |
|
||||||
|
| `g:plug_retries` | 2 | Number of retries in case of timeout |
|
||||||
|
|
||||||
### Keybindings
|
### Keybindings
|
||||||
|
|
||||||
|
|
9
plug.vim
9
plug.vim
|
@ -610,6 +610,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||||
base = VIM::evaluate('g:plug_home')
|
base = VIM::evaluate('g:plug_home')
|
||||||
all = VIM::evaluate('copy(a:todo)')
|
all = VIM::evaluate('copy(a:todo)')
|
||||||
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
||||||
|
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
|
||||||
nthr = VIM::evaluate('a:threads').to_i
|
nthr = VIM::evaluate('a:threads').to_i
|
||||||
maxy = VIM::evaluate('winheight(".")').to_i
|
maxy = VIM::evaluate('winheight(".")').to_i
|
||||||
cd = iswin ? 'cd /d' : 'cd'
|
cd = iswin ? 'cd /d' : 'cd'
|
||||||
|
@ -652,11 +653,14 @@ function! s:update_parallel(pull, todo, threads)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
bt = proc { |cmd, name, type|
|
bt = proc { |cmd, name, type|
|
||||||
|
tried = timeout = 0
|
||||||
begin
|
begin
|
||||||
|
tried += 1
|
||||||
|
timeout += limit
|
||||||
fd = nil
|
fd = nil
|
||||||
data = ''
|
data = ''
|
||||||
if iswin
|
if iswin
|
||||||
Timeout::timeout(limit) do
|
Timeout::timeout(timeout) do
|
||||||
tmp = VIM::evaluate('tempname()')
|
tmp = VIM::evaluate('tempname()')
|
||||||
system("#{cmd} > #{tmp}")
|
system("#{cmd} > #{tmp}")
|
||||||
data = File.read(tmp).chomp
|
data = File.read(tmp).chomp
|
||||||
|
@ -666,7 +670,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||||
fd = IO.popen(cmd).extend(PlugStream)
|
fd = IO.popen(cmd).extend(PlugStream)
|
||||||
first_line = true
|
first_line = true
|
||||||
log_prob = 1.0 / nthr
|
log_prob = 1.0 / nthr
|
||||||
while line = Timeout::timeout(limit) { fd.get_line }
|
while line = Timeout::timeout(timeout) { fd.get_line }
|
||||||
data << line
|
data << line
|
||||||
log.call name, line.chomp, type if name && (first_line || rand < log_prob)
|
log.call name, line.chomp, type if name && (first_line || rand < log_prob)
|
||||||
first_line = false
|
first_line = false
|
||||||
|
@ -689,6 +693,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||||
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
||||||
fd.close
|
fd.close
|
||||||
end
|
end
|
||||||
|
retry if e.is_a?(Timeout::Error) && tried < tries
|
||||||
[false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"]
|
[false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"]
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user