Add retry feature to project import

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-03-12 19:26:09 +02:00
parent 37db76a31b
commit b47646ef13
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
4 changed files with 28 additions and 6 deletions

View file

@ -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

View file

@ -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,

View file

@ -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)

View file

@ -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