Changed concurrent removal to take into account real removals, not removal checks

This commit is contained in:
Adolfo Gómez García 2022-01-03 14:07:46 +01:00
parent 8be0d9702a
commit 4809252434

View File

@ -74,9 +74,10 @@ class UserServiceRemover(Job):
friendly_name = 'User Service Cleaner'
def run(self) -> None:
removeAtOnce: int = (
GlobalConfig.USER_SERVICE_CLEAN_NUMBER.getInt()
) # Same, it will work at reload
# USER_SERVICE_REMOVAL_LIMIT is the maximum number of items to remove at once
# This configuration value is cached at startup, so it is not updated until next reload
removeAtOnce: int = GlobalConfig.USER_SERVICE_CLEAN_NUMBER.getInt()
manager = managers.userServiceManager()
with transaction.atomic():
removeFrom = getSqlDatetime() - timedelta(
@ -88,17 +89,19 @@ class UserServiceRemover(Job):
state=State.REMOVABLE,
state_date__lt=removeFrom,
deployed_service__service__provider__maintenance_mode=False,
)[
0:removeAtOnce
].iterator()
).iterator(chunk_size=removeAtOnce)
# We remove at once, but we limit the number of items to remove
manager = managers.userServiceManager()
for removableUserService in removableUserServices:
if removeAtOnce <= 0:
break
logger.debug('Checking removal of %s', removableUserService.name)
try:
if manager.canRemoveServiceFromDeployedService(
removableUserService.deployed_service
):
manager.remove(removableUserService)
removeAtOnce -= 1 # We promoted one removal
except Exception:
logger.exception('Exception removing user service')