Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-09-01 10:56:40 +0300
committerStan Hu <stanhu@gmail.com>2015-09-11 10:34:04 +0300
commit9995f0806b29934cf498607f59d2c5ec358a0d5a (patch)
treead197f6e023553b20bb1317c57dddffe34da68b5 /app/models
parenta5bb85f8a234b2d8463656877712faf10f5bb842 (diff)
Import forked repositories asynchronously to prevent large repositories from timing out
Use import_status to track async import status and give feedback to the user Closes #2388 Closes #2400
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 072d7d73f41..49525eb9227 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -144,7 +144,7 @@ class Project < ActiveRecord::Base
validates_uniqueness_of :path, scope: :namespace_id
validates :import_url,
format: { with: /\A#{URI.regexp(%w(ssh git http https))}\z/, message: 'should be a valid url' },
- if: :import?
+ if: :external_import?
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
validate :avatar_type,
@@ -275,7 +275,13 @@ class Project < ActiveRecord::Base
end
def add_import_job
- RepositoryImportWorker.perform_in(2.seconds, id)
+ if forked?
+ unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path)
+ import_fail
+ end
+ else
+ RepositoryImportWorker.perform_in(2.seconds, id)
+ end
end
def clear_import_data
@@ -283,6 +289,10 @@ class Project < ActiveRecord::Base
end
def import?
+ external_import? || forked?
+ end
+
+ def external_import?
import_url.present?
end
@@ -702,14 +712,8 @@ class Project < ActiveRecord::Base
end
def create_repository
- if forked?
- if gitlab_shell.fork_repository(forked_from_project.path_with_namespace, self.namespace.path)
- true
- else
- errors.add(:base, 'Failed to fork repository via gitlab-shell')
- false
- end
- else
+ # Forked import is handled asynchronously
+ unless forked?
if gitlab_shell.add_repository(path_with_namespace)
true
else