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 | 126 | end |
127 | 127 | |
128 | 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 | 134 | end |
131 | 135 | |
132 | 136 | state :started |
133 | 137 | state :finished |
134 | - state :timeout | |
138 | + state :failed | |
139 | + | |
140 | + after_transition any => :started, :do => :add_import_job | |
135 | 141 | end |
136 | 142 | |
137 | 143 | class << self |
... | ... | @@ -210,12 +216,28 @@ class Project < ActiveRecord::Base |
210 | 216 | id && persisted? |
211 | 217 | end |
212 | 218 | |
219 | + def add_import_job | |
220 | + RepositoryImportWorker.perform_in(2.seconds, id) | |
221 | + end | |
222 | + | |
213 | 223 | def import? |
214 | 224 | import_url.present? |
215 | 225 | end |
216 | 226 | |
217 | 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 | 241 | end |
220 | 242 | |
221 | 243 | def check_limit | ... | ... |
app/services/projects/create_service.rb
... | ... | @@ -62,7 +62,7 @@ module Projects |
62 | 62 | @project.update_column(:last_activity_at, @project.created_at) |
63 | 63 | |
64 | 64 | if @project.import? |
65 | - RepositoryImportWorker.perform_in(5.seconds, @project.id) | |
65 | + @project.import_start | |
66 | 66 | else |
67 | 67 | GitlabShellWorker.perform_async( |
68 | 68 | :add_repository, | ... | ... |
app/workers/repository_import_worker.rb