forked from shaba/openuds
Changed concurrent removal to take into account real removals, not removal checks
This commit is contained in:
parent
8be0d9702a
commit
4809252434
@ -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
|
||||||
@ -88,17 +89,19 @@ class UserServiceRemover(Job):
|
|||||||
state=State.REMOVABLE,
|
state=State.REMOVABLE,
|
||||||
state_date__lt=removeFrom,
|
state_date__lt=removeFrom,
|
||||||
deployed_service__service__provider__maintenance_mode=False,
|
deployed_service__service__provider__maintenance_mode=False,
|
||||||
)[
|
).iterator(chunk_size=removeAtOnce)
|
||||||
0:removeAtOnce
|
|
||||||
].iterator()
|
# We remove at once, but we limit the number of items to remove
|
||||||
|
|
||||||
manager = managers.userServiceManager()
|
|
||||||
for removableUserService in removableUserServices:
|
for removableUserService in removableUserServices:
|
||||||
|
if removeAtOnce <= 0:
|
||||||
|
break
|
||||||
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')
|
||||||
|
Loading…
Reference in New Issue
Block a user