diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 14:39:26 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 14:39:26 +0000 |
commit | 0f4ad24ff2f3ff375153b2e6535f1fd2ca467401 (patch) | |
tree | 1a4378fb5f372b4fc1e7e7a7fc0a16b687ab89b9 /lib/gitlab_projects.rb | |
parent | d207d69ba2d74856b81f8c88159cdcdde36d37ca (diff) | |
parent | 323545fc87a5527867b9f276d8efc29a27a1468d (diff) | |
download | gitlab-shell-0f4ad24ff2f3ff375153b2e6535f1fd2ca467401.tar.gz |
Merge branch 'import-timeout' into 'master'v1.8.3
Import Timeout
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index a0063aa..38a3a7d 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'timeout' require_relative 'gitlab_config' require_relative 'gitlab_logger' @@ -92,9 +93,26 @@ class GitlabProjects # URL must be publicly cloneable def import_project @source = ARGV.shift + + # timeout for clone + timeout = (ARGV.shift || 120).to_i $logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>." cmd = %W(git clone --bare -- #{@source} #{full_path}) - system(*cmd) && self.class.create_hooks(full_path) + + pid = Process.spawn(*cmd) + + begin + Timeout.timeout(timeout) do + Process.wait(pid) + end + rescue Timeout::Error + Process.kill('KILL', pid) + $logger.error "Importing project #{@project_name} from <#{@source}> failed due to timeout." + FileUtils.rm_rf(full_path) + false + else + self.class.create_hooks(full_path) + end end # Move repository from one directory to another |