change run deletion (session/synchronize)
* use separate sessions for each run deletion
* wich the synchronize_session=False deletion can be speed up
because we do not need the runs in the session anymore,
just cleaning up everything
@@ -1703,10 +1703,10 @@ class ThriftRequestHandler(object):
def removeRunResults(self, run_ids):
self.__require_store()
- with DBSession(self.__Session) as session:
-
- runs_to_delete = []
+ 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)
@@ -1718,7 +1718,8 @@ class ThriftRequestHandler(object):
# 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)
+ 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) \
@@ -1729,20 +1730,25 @@ class ThriftRequestHandler(object):
continue
run_to_delete.can_delete = False
+ # Commmit the can_delete flag.
session.commit()
- runs_to_delete.append(run_to_delete)
- 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()
+ session.query(Run)\
+ .filter(Run.id == run_id)\
+ .delete(synchronize_session=False)
- # Delete files and contents that are not present in any bug paths.
+ # Delete files and contents that are not present
+ # in any bug paths.
db_cleanup.remove_unused_files(session)
session.commit()
session.close()
- return True
+
+ except Exception as ex:
+ LOG.error("Failed to remove run: " + str(run_id))
+ LOG.error(ex)
+ failed = True
+
+ return not failed
# -----------------------------------------------------------------------
@exc_to_thrift_reqfail
