Add retry feature to project import
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
37db76a31b
commit
b47646ef13
4 changed files with 28 additions and 6 deletions
|
@ -126,12 +126,18 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
event :import_fail do
|
||||
transition :started => :timeout
|
||||
transition :started => :failed
|
||||
end
|
||||
|
||||
event :import_retry do
|
||||
transition :failed => :started
|
||||
end
|
||||
|
||||
state :started
|
||||
state :finished
|
||||
state :timeout
|
||||
state :failed
|
||||
|
||||
after_transition any => :started, :do => :add_import_job
|
||||
end
|
||||
|
||||
class << self
|
||||
|
@ -210,12 +216,28 @@ class Project < ActiveRecord::Base
|
|||
id && persisted?
|
||||
end
|
||||
|
||||
def add_import_job
|
||||
RepositoryImportWorker.perform_in(2.seconds, id)
|
||||
end
|
||||
|
||||
def import?
|
||||
import_url.present?
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def check_limit
|
||||
|
|
|
@ -62,7 +62,7 @@ module Projects
|
|||
@project.update_column(:last_activity_at, @project.created_at)
|
||||
|
||||
if @project.import?
|
||||
RepositoryImportWorker.perform_in(5.seconds, @project.id)
|
||||
@project.import_start
|
||||
else
|
||||
GitlabShellWorker.perform_async(
|
||||
:add_repository,
|
||||
|
|
|
@ -6,8 +6,6 @@ class RepositoryImportWorker
|
|||
|
||||
def perform(project_id)
|
||||
project = Project.find(project_id)
|
||||
project.import_start
|
||||
|
||||
result = gitlab_shell.send(:import_repository,
|
||||
project.path_with_namespace,
|
||||
project.import_url)
|
||||
|
|
|
@ -179,6 +179,8 @@ Gitlab::Application.routes.draw do
|
|||
post :archive
|
||||
post :unarchive
|
||||
get :autocomplete_sources
|
||||
get :import
|
||||
put :retry_import
|
||||
end
|
||||
|
||||
scope module: :projects do
|
||||
|
|
Loading…
Reference in a new issue