diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 19:26:09 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-12 19:26:09 +0200 |
commit | b47646ef13597836cad342a4d9372316289f0155 (patch) | |
tree | 3cfdfd869113720407d2d1da8dd49ebd4ffc168f /app | |
parent | 37db76a31b8d9676aeadcaf6e2e175ead0f68d74 (diff) | |
download | gitlab-ce-b47646ef13597836cad342a4d9372316289f0155.tar.gz |
Add retry feature to project import
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 28 | ||||
-rw-r--r-- | app/services/projects/create_service.rb | 2 | ||||
-rw-r--r-- | app/workers/repository_import_worker.rb | 2 |
3 files changed, 26 insertions, 6 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 90c33822568..c2ba21ac7e9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index b3f97a7c9c1..4d3d518a509 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -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, diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb index c577cb0273f..e66df8c4db1 100644 --- a/app/workers/repository_import_worker.rb +++ b/app/workers/repository_import_worker.rb @@ -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) |