Commit b47646ef authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add retry feature to project import

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 37db76a3
...@@ -126,12 +126,18 @@ class Project < ActiveRecord::Base ...@@ -126,12 +126,18 @@ class Project < ActiveRecord::Base
end end
event :import_fail do event :import_fail do
transition :started => :timeout transition :started => :failed
end
event :import_retry do
transition :failed => :started
end end
state :started state :started
state :finished state :finished
state :timeout state :failed
after_transition any => :started, :do => :add_import_job
end end
class << self class << self
...@@ -210,12 +216,28 @@ class Project < ActiveRecord::Base ...@@ -210,12 +216,28 @@ class Project < ActiveRecord::Base
id && persisted? id && persisted?
end end
def add_import_job
RepositoryImportWorker.perform_in(2.seconds, id)
end
def import? def import?
import_url.present? import_url.present?
end end
def imported? def imported?
imported import_finished?
end
def import_in_progress?
import? && import_status == 'started'
end
def import_failed?
import_status == 'failed'
end
def import_finished?
import_status == 'finished'
end end
def check_limit def check_limit
......
...@@ -62,7 +62,7 @@ module Projects ...@@ -62,7 +62,7 @@ module Projects
@project.update_column(:last_activity_at, @project.created_at) @project.update_column(:last_activity_at, @project.created_at)
if @project.import? if @project.import?
RepositoryImportWorker.perform_in(5.seconds, @project.id) @project.import_start
else else
GitlabShellWorker.perform_async( GitlabShellWorker.perform_async(
:add_repository, :add_repository,
......
...@@ -6,8 +6,6 @@ class RepositoryImportWorker ...@@ -6,8 +6,6 @@ class RepositoryImportWorker
def perform(project_id) def perform(project_id)
project = Project.find(project_id) project = Project.find(project_id)
project.import_start
result = gitlab_shell.send(:import_repository, result = gitlab_shell.send(:import_repository,
project.path_with_namespace, project.path_with_namespace,
project.import_url) project.import_url)
......
...@@ -179,6 +179,8 @@ Gitlab::Application.routes.draw do ...@@ -179,6 +179,8 @@ Gitlab::Application.routes.draw do
post :archive post :archive
post :unarchive post :unarchive
get :autocomplete_sources get :autocomplete_sources
get :import
put :retry_import
end end
scope module: :projects do scope module: :projects do
......
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