##// END OF EJS Templates
celery: tasks, improve fork/repo create to survive a database errors in the cleanup code.
marcink -
r2419:20304eec default
parent child Browse files
Show More
@@ -32,7 +32,7 b' from rhodecode.lib.celerylib import get_'
32 32 from rhodecode.lib.hooks_base import log_create_repository
33 33 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
34 34 from rhodecode.lib.utils2 import safe_int, str2bool
35 from rhodecode.model.db import Session, Repository, User
35 from rhodecode.model.db import Session, IntegrityError, Repository, User
36 36
37 37
38 38 @async_task(ignore_result=True, base=RequestContextTask)
@@ -159,21 +159,21 b' def create_repo(form_data, cur_user):'
159 159 repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id))
160 160
161 161 Session().commit()
162 except Exception:
162 except Exception as e:
163 163 log.warning('Exception occurred when creating repository, '
164 164 'doing cleanup...', exc_info=True)
165 if isinstance(e, IntegrityError):
166 Session().rollback()
167
165 168 # rollback things manually !
166 169 repo = Repository.get_by_repo_name(repo_name_full)
167 170 if repo:
168 171 Repository.delete(repo.repo_id)
169 172 Session().commit()
170 173 RepoModel()._delete_filesystem_repo(repo)
174 log.info('Cleanup of repo %s finished', repo_name_full)
171 175 raise
172 176
173 # it's an odd fix to make celery fail task when exception occurs
174 def on_failure(self, *args, **kwargs):
175 pass
176
177 177 return True
178 178
179 179
@@ -249,19 +249,19 b' def create_repo_fork(form_data, cur_user'
249 249 Session().commit()
250 250 except Exception as e:
251 251 log.warning('Exception %s occurred when forking repository, '
252 'doing cleanup...', e)
252 'doing cleanup...', exc_info=True)
253 if isinstance(e, IntegrityError):
254 Session().rollback()
255
253 256 # rollback things manually !
254 257 repo = Repository.get_by_repo_name(repo_name_full)
255 258 if repo:
256 259 Repository.delete(repo.repo_id)
257 260 Session().commit()
258 261 RepoModel()._delete_filesystem_repo(repo)
262 log.info('Cleanup of repo %s finished', repo_name_full)
259 263 raise
260 264
261 # it's an odd fix to make celery fail task when exception occurs
262 def on_failure(self, *args, **kwargs):
263 pass
264
265 265 return True
266 266
267 267
General Comments 0
You need to be logged in to leave comments. Login now