From 3323163e044f2cc8c90bf9fd193f51414cbb7236 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 20 Jul 2014 02:14:15 +0900 Subject: [PATCH 1/2] Retry in case of timeout (#35) while gradually increasing the time limit --- README.md | 9 +++++---- plug.vim | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ce7eecc..aba3aef 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,11 @@ before the call. ### Options for parallel installer -| Flag | Default | Description | -| ---------------- | ------- | --------------------------------- | -| `g:plug_threads` | 16 | Default number of threads to use | -| `g:plug_timeout` | 60 | Time limit of each task in seconds | +| Flag | Default | Description | +| ---------------- | ------- | ------------------------------------ | +| `g:plug_threads` | 16 | Default number of threads to use | +| `g:plug_timeout` | 60 | Time limit of each task in seconds | +| `g:plug_retries` | 2 | Number of retries in case of timeout | ### Keybindings diff --git a/plug.vim b/plug.vim index ea5dfee..14f6d9d 100644 --- a/plug.vim +++ b/plug.vim @@ -610,6 +610,7 @@ function! s:update_parallel(pull, todo, threads) base = VIM::evaluate('g:plug_home') all = VIM::evaluate('copy(a:todo)') limit = VIM::evaluate('get(g:, "plug_timeout", 60)') + tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1 nthr = VIM::evaluate('a:threads').to_i maxy = VIM::evaluate('winheight(".")').to_i cd = iswin ? 'cd /d' : 'cd' @@ -652,11 +653,14 @@ function! s:update_parallel(pull, todo, threads) end } bt = proc { |cmd, name, type| + tried = timeout = 0 begin + tried += 1 + timeout += limit fd = nil data = '' if iswin - Timeout::timeout(limit) do + Timeout::timeout(timeout) do tmp = VIM::evaluate('tempname()') system("#{cmd} > #{tmp}") data = File.read(tmp).chomp @@ -666,7 +670,7 @@ function! s:update_parallel(pull, todo, threads) fd = IO.popen(cmd).extend(PlugStream) first_line = true log_prob = 1.0 / nthr - while line = Timeout::timeout(limit) { fd.get_line } + while line = Timeout::timeout(timeout) { fd.get_line } data << line log.call name, line.chomp, type if name && (first_line || rand < log_prob) 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 } fd.close end + retry if e.is_a?(Timeout::Error) && tried < tries [false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"] end } From e2714fb56e854f4aef0d918a89690c3127981465 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 21 Jul 2014 23:09:16 +0900 Subject: [PATCH 2/2] Retry in 3 seconds --- plug.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plug.vim b/plug.vim index 14f6d9d..a008a6a 100644 --- a/plug.vim +++ b/plug.vim @@ -693,7 +693,15 @@ function! s:update_parallel(pull, todo, threads) pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } fd.close end - retry if e.is_a?(Timeout::Error) && tried < tries + if e.is_a?(Timeout::Error) && tried < tries + 3.downto(1) do |countdown| + s = countdown > 1 ? 's' : '' + log.call name, "Timeout. Will retry in #{countdown} second#{s} ...", type + sleep 1 + end + log.call name, 'Retrying ...', type + retry + end [false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"] end }