diff --git a/libcodechecker/server/api/report_server.py b/libcodechecker/server/api/report_server.py index ab03f18566..5531cbc48c 100644 --- a/libcodechecker/server/api/report_server.py +++ b/libcodechecker/server/api/report_server.py @@ -1703,46 +1703,52 @@ def getPackageVersion(self): def removeRunResults(self, run_ids): self.__require_store() - with DBSession(self.__Session) as session: - - runs_to_delete = [] - for run_id in run_ids: - LOG.debug('Run id to delete: ' + str(run_id)) - - run_to_delete = session.query(Run).get(run_id) - if not run_to_delete.can_delete: - LOG.debug("Can't delete " + str(run_id)) - continue + failed = False + for run_id in run_ids: + try: + with DBSession(self.__Session) as session: + LOG.debug('Run id to delete: ' + str(run_id)) + + run_to_delete = session.query(Run).get(run_id) + if not run_to_delete.can_delete: + LOG.debug("Can't delete " + str(run_id)) + continue + + # Check if there is an existing lock on the given run name, + # which has not expired yet. If so, the run cannot be + # deleted, as someone is assumed to be storing into it. + locks_expired_at = datetime.now() - \ + timedelta( + seconds=db_cleanup.RUN_LOCK_TIMEOUT_IN_DATABASE) + lock = session.query(RunLock) \ + .filter(RunLock.name == run_to_delete.name, + RunLock.locked_at >= locks_expired_at) \ + .one_or_none() + if lock: + LOG.info("Can't delete '{0}' as it is locked." + .format(run_to_delete.name)) + continue + + run_to_delete.can_delete = False + # Commmit the can_delete flag. + session.commit() - # Check if there is an existing lock on the given run name, - # which has not expired yet. If so, the run cannot be - # deleted, as someone is assumed to be storing into it. - locks_expired_at = datetime.now() - \ - timedelta(seconds=db_cleanup.RUN_LOCK_TIMEOUT_IN_DATABASE) - lock = session.query(RunLock) \ - .filter(RunLock.name == run_to_delete.name, - RunLock.locked_at >= locks_expired_at) \ - .one_or_none() - if lock: - LOG.info("Can't delete '{0}' as it is locked." - .format(run_to_delete.name)) - continue + session.query(Run)\ + .filter(Run.id == run_id)\ + .delete(synchronize_session=False) - run_to_delete.can_delete = False - session.commit() - runs_to_delete.append(run_to_delete) + # Delete files and contents that are not present + # in any bug paths. + db_cleanup.remove_unused_files(session) + session.commit() + session.close() - for run_to_delete in runs_to_delete: - # FIXME: clean up bugpaths. Once run_id is a foreign key there, - # it should be automatic. - session.delete(run_to_delete) - session.commit() + except Exception as ex: + LOG.error("Failed to remove run: " + str(run_id)) + LOG.error(ex) + failed = True - # Delete files and contents that are not present in any bug paths. - db_cleanup.remove_unused_files(session) - session.commit() - session.close() - return True + return not failed # ----------------------------------------------------------------------- @exc_to_thrift_reqfail