Commit b47646ef13597836cad342a4d9372316289f0155
1 parent
37db76a3
Exists in
spb-stable
and in
3 other branches
Add retry feature to project import
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
28 additions
and
6 deletions
Show diff stats
app/models/project.rb
| @@ -126,12 +126,18 @@ class Project < ActiveRecord::Base | @@ -126,12 +126,18 @@ class Project < ActiveRecord::Base | ||
| 126 | end | 126 | end |
| 127 | 127 | ||
| 128 | event :import_fail do | 128 | event :import_fail do |
| 129 | - transition :started => :timeout | 129 | + transition :started => :failed |
| 130 | + end | ||
| 131 | + | ||
| 132 | + event :import_retry do | ||
| 133 | + transition :failed => :started | ||
| 130 | end | 134 | end |
| 131 | 135 | ||
| 132 | state :started | 136 | state :started |
| 133 | state :finished | 137 | state :finished |
| 134 | - state :timeout | 138 | + state :failed |
| 139 | + | ||
| 140 | + after_transition any => :started, :do => :add_import_job | ||
| 135 | end | 141 | end |
| 136 | 142 | ||
| 137 | class << self | 143 | class << self |
| @@ -210,12 +216,28 @@ class Project < ActiveRecord::Base | @@ -210,12 +216,28 @@ class Project < ActiveRecord::Base | ||
| 210 | id && persisted? | 216 | id && persisted? |
| 211 | end | 217 | end |
| 212 | 218 | ||
| 219 | + def add_import_job | ||
| 220 | + RepositoryImportWorker.perform_in(2.seconds, id) | ||
| 221 | + end | ||
| 222 | + | ||
| 213 | def import? | 223 | def import? |
| 214 | import_url.present? | 224 | import_url.present? |
| 215 | end | 225 | end |
| 216 | 226 | ||
| 217 | def imported? | 227 | def imported? |
| 218 | - imported | 228 | + import_finished? |
| 229 | + end | ||
| 230 | + | ||
| 231 | + def import_in_progress? | ||
| 232 | + import? && import_status == 'started' | ||
| 233 | + end | ||
| 234 | + | ||
| 235 | + def import_failed? | ||
| 236 | + import_status == 'failed' | ||
| 237 | + end | ||
| 238 | + | ||
| 239 | + def import_finished? | ||
| 240 | + import_status == 'finished' | ||
| 219 | end | 241 | end |
| 220 | 242 | ||
| 221 | def check_limit | 243 | def check_limit |
app/services/projects/create_service.rb
| @@ -62,7 +62,7 @@ module Projects | @@ -62,7 +62,7 @@ module Projects | ||
| 62 | @project.update_column(:last_activity_at, @project.created_at) | 62 | @project.update_column(:last_activity_at, @project.created_at) |
| 63 | 63 | ||
| 64 | if @project.import? | 64 | if @project.import? |
| 65 | - RepositoryImportWorker.perform_in(5.seconds, @project.id) | 65 | + @project.import_start |
| 66 | else | 66 | else |
| 67 | GitlabShellWorker.perform_async( | 67 | GitlabShellWorker.perform_async( |
| 68 | :add_repository, | 68 | :add_repository, |
app/workers/repository_import_worker.rb
| @@ -6,8 +6,6 @@ class RepositoryImportWorker | @@ -6,8 +6,6 @@ class RepositoryImportWorker | ||
| 6 | 6 | ||
| 7 | def perform(project_id) | 7 | def perform(project_id) |
| 8 | project = Project.find(project_id) | 8 | project = Project.find(project_id) |
| 9 | - project.import_start | ||
| 10 | - | ||
| 11 | result = gitlab_shell.send(:import_repository, | 9 | result = gitlab_shell.send(:import_repository, |
| 12 | project.path_with_namespace, | 10 | project.path_with_namespace, |
| 13 | project.import_url) | 11 | project.import_url) |
config/routes.rb
| @@ -179,6 +179,8 @@ Gitlab::Application.routes.draw do | @@ -179,6 +179,8 @@ Gitlab::Application.routes.draw do | ||
| 179 | post :archive | 179 | post :archive |
| 180 | post :unarchive | 180 | post :unarchive |
| 181 | get :autocomplete_sources | 181 | get :autocomplete_sources |
| 182 | + get :import | ||
| 183 | + put :retry_import | ||
| 182 | end | 184 | end |
| 183 | 185 | ||
| 184 | scope module: :projects do | 186 | scope module: :projects do |