##// 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 from rhodecode.lib.hooks_base import log_create_repository
32 from rhodecode.lib.hooks_base import log_create_repository
33 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
33 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
34 from rhodecode.lib.utils2 import safe_int, str2bool
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 @async_task(ignore_result=True, base=RequestContextTask)
38 @async_task(ignore_result=True, base=RequestContextTask)
@@ -159,21 +159,21 b' def create_repo(form_data, cur_user):'
159 repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id))
159 repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id))
160
160
161 Session().commit()
161 Session().commit()
162 except Exception:
162 except Exception as e:
163 log.warning('Exception occurred when creating repository, '
163 log.warning('Exception occurred when creating repository, '
164 'doing cleanup...', exc_info=True)
164 'doing cleanup...', exc_info=True)
165 if isinstance(e, IntegrityError):
166 Session().rollback()
167
165 # rollback things manually !
168 # rollback things manually !
166 repo = Repository.get_by_repo_name(repo_name_full)
169 repo = Repository.get_by_repo_name(repo_name_full)
167 if repo:
170 if repo:
168 Repository.delete(repo.repo_id)
171 Repository.delete(repo.repo_id)
169 Session().commit()
172 Session().commit()
170 RepoModel()._delete_filesystem_repo(repo)
173 RepoModel()._delete_filesystem_repo(repo)
174 log.info('Cleanup of repo %s finished', repo_name_full)
171 raise
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 return True
177 return True
178
178
179
179
@@ -249,19 +249,19 b' def create_repo_fork(form_data, cur_user'
249 Session().commit()
249 Session().commit()
250 except Exception as e:
250 except Exception as e:
251 log.warning('Exception %s occurred when forking repository, '
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 # rollback things manually !
256 # rollback things manually !
254 repo = Repository.get_by_repo_name(repo_name_full)
257 repo = Repository.get_by_repo_name(repo_name_full)
255 if repo:
258 if repo:
256 Repository.delete(repo.repo_id)
259 Repository.delete(repo.repo_id)
257 Session().commit()
260 Session().commit()
258 RepoModel()._delete_filesystem_repo(repo)
261 RepoModel()._delete_filesystem_repo(repo)
262 log.info('Cleanup of repo %s finished', repo_name_full)
259 raise
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 return True
265 return True
266
266
267
267
General Comments 0
You need to be logged in to leave comments. Login now