Merge remote-tracking branch 'origin/v3.5'

This commit is contained in:
Adolfo Gómez García 2022-01-03 14:10:26 +01:00
commit a071e2e8f5

View File

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