Commit 7ecebdd0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Repository import during project creation often return timeout for medium and large repos.

So lets do it async. First create project, then import repo and create
satellite with Sidekiq
parent e2f946fd
...@@ -45,20 +45,6 @@ module Projects ...@@ -45,20 +45,6 @@ module Projects
@project.creator = current_user @project.creator = current_user
# Import project from cloneable resource
if @project.valid? && @project.import_url.present?
shell = Gitlab::Shell.new
if shell.import_repository(@project.path_with_namespace, @project.import_url)
# We should create satellite for imported repo
@project.satellite.create unless @project.satellite.exists?
@project.imported = true
true
else
@project.errors.add(:import_url, 'cannot clone repo')
end
end
if @project.save if @project.save
unless @project.group unless @project.group
@project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) @project.users_projects.create(project_access: UsersProject::MASTER, user: current_user)
......
...@@ -37,8 +37,6 @@ class Project < ActiveRecord::Base ...@@ -37,8 +37,6 @@ class Project < ActiveRecord::Base
acts_as_taggable_on :labels, :issues_default_labels acts_as_taggable_on :labels, :issues_default_labels
attr_accessor :import_url
# Relations # Relations
belongs_to :creator, foreign_key: "creator_id", class_name: "User" belongs_to :creator, foreign_key: "creator_id", class_name: "User"
belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'"
...@@ -157,6 +155,10 @@ class Project < ActiveRecord::Base ...@@ -157,6 +155,10 @@ class Project < ActiveRecord::Base
import_url.present? import_url.present?
end end
def imported?
imported
end
def check_limit def check_limit
unless creator.can_create_project? unless creator.can_create_project?
errors[:limit_reached] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it") errors[:limit_reached] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it")
...@@ -411,10 +413,6 @@ class Project < ActiveRecord::Base ...@@ -411,10 +413,6 @@ class Project < ActiveRecord::Base
!(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?)
end end
def imported?
imported
end
def personal? def personal?
!group !group
end end
......
class ProjectObserver < BaseObserver class ProjectObserver < BaseObserver
def after_create(project) def after_create(project)
return true if project.forked? || project.imported? return true if project.forked?
GitlabShellWorker.perform_async( if project.import?
:add_repository, RepositoryImportWorker.perform_in(5.seconds, project.id)
project.path_with_namespace else
) GitlabShellWorker.perform_async(
:add_repository,
log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"") project.path_with_namespace
)
log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
end
end end
def after_update(project) def after_update(project)
......
= render 'clone_panel' = render 'clone_panel'
%div.git-empty - if @project.import? && !@project.imported
%fieldset .save-project-loader
%legend Git global setup: %center
%pre.dark = image_tag "ajax_loader.gif"
:preserve %h3 Importing repository.
git config --global user.name "#{current_user.name}" %p.monospace git clone --bare #{@project.import_url}
git config --global user.email "#{current_user.email}" %p Please wait until we import repository for you. Refresh at will.
%fieldset - else
%legend Create Repository %div.git-empty
%pre.dark %fieldset
:preserve %legend Git global setup:
mkdir #{@project.path} %pre.dark
cd #{@project.path} :preserve
git init git config --global user.name "#{current_user.name}"
touch README git config --global user.email "#{current_user.email}"
git add README
git commit -m 'first commit'
git remote add origin #{@project.url_to_repo}
git push -u origin master
%fieldset %fieldset
%legend Existing Git Repo? %legend Create Repository
%pre.dark %pre.dark
:preserve :preserve
cd existing_git_repo mkdir #{@project.path}
git remote add origin #{@project.url_to_repo} cd #{@project.path}
git push -u origin master git init
touch README
git add README
git commit -m 'first commit'
git remote add origin #{@project.url_to_repo}
git push -u origin master
%fieldset
%legend Existing Git Repo?
%pre.dark
:preserve
cd existing_git_repo
git remote add origin #{@project.url_to_repo}
git push -u origin master
- if can? current_user, :remove_project, @project - if can? current_user, :remove_project, @project
.prepend-top-20 .prepend-top-20
......
class RepositoryImportWorker
include Sidekiq::Worker
include Gitlab::ShellAdapter
sidekiq_options queue: :gitlab_shell
def perform(project_id)
project = Project.find(project_id)
result = gitlab_shell.send(:import_repository,
project.path_with_namespace,
project.import_url)
if result
project.imported = true
project.save
project.satellite.create unless project.satellite.exists?
project.discover_default_branch
else
project.imported = false
end
end
end
class AddImportUrlToProject < ActiveRecord::Migration
def change
add_column :projects, :import_url, :string
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130804151314) do ActiveRecord::Schema.define(:version => 20130812143708) do
create_table "deploy_keys_projects", :force => true do |t| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
...@@ -178,6 +178,7 @@ ActiveRecord::Schema.define(:version => 20130804151314) do ...@@ -178,6 +178,7 @@ ActiveRecord::Schema.define(:version => 20130804151314) do
t.boolean "snippets_enabled", :default => true, :null => false t.boolean "snippets_enabled", :default => true, :null => false
t.datetime "last_activity_at" t.datetime "last_activity_at"
t.boolean "imported", :default => false, :null => false t.boolean "imported", :default => false, :null => false
t.string "import_url"
end end
add_index "projects", ["creator_id"], :name => "index_projects_on_owner_id" add_index "projects", ["creator_id"], :name => "index_projects_on_owner_id"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment