diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 11:03:07 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 11:03:07 +0200 |
commit | c8a713cbde5c9149539bba51917bd094ef2b5189 (patch) | |
tree | 12bfe1042f16aeaf4f444543e6b239f6d440b183 /lib/gitlab_projects.rb | |
parent | 3df553676aca6f07864c3c7bbd4422e4d70b454c (diff) | |
download | gitlab-shell-c8a713cbde5c9149539bba51917bd094ef2b5189.tar.gz |
Add support for import repo timeout
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index a0063aa..d761026 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,23 @@ 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) + + begin + Timeout.timeout(timeout) do + system(*cmd) + end + rescue + $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 |