diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-16 10:47:01 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-16 20:46:06 +0000 |
commit | c797f0b09ab0a9bbb9cd1e5e5f923436bd1ec526 (patch) | |
tree | d33e2a121963bc92e1b840299118a6fb9c39f160 /lib/gitlab_projects.rb | |
parent | f61bdfe39c6b0618144f369d5cf4df1099be9948 (diff) | |
download | gitlab-shell-adds-timeout-to-push-branches.tar.gz |
adds timeout option to push branches and respective test suiteadds-timeout-to-push-branches
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index 505b49e..f24fb26 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -113,16 +113,21 @@ class GitlabProjects def push_branches remote_name = ARGV.shift + # timeout for push + timeout = (ARGV.shift || 120).to_i + $logger.info "Pushing branches from #{full_path} to remote #{remote_name}: #{ARGV}" cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(ARGV) pid = Process.spawn(*cmd) begin - Process.wait(pid) + Timeout.timeout(timeout) do + Process.wait(pid) + end $?.exitstatus.zero? - rescue => exception - $logger.error "Pushing branches to remote #{remote_name} failed due to: #{exception.message}" + rescue Timeout::Error + $logger.error "Pushing branches to remote #{remote_name} failed due to timeout." Process.kill('KILL', pid) Process.wait @@ -204,8 +209,7 @@ class GitlabProjects tags_option = ARGV.include?('--no-tags') ? '--no-tags' : '--tags' $logger.info "Fetching remote #{@name} for project #{@project_name}." - cmd = %W(git --git-dir=#{full_path} fetch #{@name}) - cmd << '--prune' + cmd = %W(git --git-dir=#{full_path} fetch #{@name} --prune) cmd << '--force' if forced cmd << tags_option pid = Process.spawn(*cmd) |