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?
if project.import?
RepositoryImportWorker.perform_in(5.seconds, project.id)
else
GitlabShellWorker.perform_async( GitlabShellWorker.perform_async(
:add_repository, :add_repository,
project.path_with_namespace project.path_with_namespace
...@@ -9,6 +12,7 @@ class ProjectObserver < BaseObserver ...@@ -9,6 +12,7 @@ class ProjectObserver < BaseObserver
log_info("#{project.owner.name} created a new project \"#{project.name_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)
project.send_move_instructions if project.namespace_id_changed? project.send_move_instructions if project.namespace_id_changed?
......
= render 'clone_panel' = render 'clone_panel'
%div.git-empty - if @project.import? && !@project.imported
.save-project-loader
%center
= image_tag "ajax_loader.gif"
%h3 Importing repository.
%p.monospace git clone --bare #{@project.import_url}
%p Please wait until we import repository for you. Refresh at will.
- else
%div.git-empty
%fieldset %fieldset
%legend Git global setup: %legend Git global setup:
%pre.dark %pre.dark
......
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