1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-03 01:17:56 +03:00

* Added new global config var for time elapsed before services in use for old publications are removed

* Added support for removal of services from old publications in use once a configured time is elapsed
This commit is contained in:
Adolfo Gómez 2013-06-19 08:33:15 +00:00
parent b2b747a099
commit 8d9b825237
4 changed files with 15 additions and 7 deletions

View File

@ -88,7 +88,7 @@ class PublicationFinishChecker(DelayedTask):
if State.isPreparing(prevState):
dsp.deployed_service.publications.filter(state=State.USABLE).update(state=State.REMOVABLE)
dsp.setState(State.USABLE)
dsp.deployed_service.markOldDeployedServicesAsRemovables(dsp)
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
elif State.isRemoving(prevState):
dsp.setState(State.REMOVED)
else: # State is canceling

View File

@ -238,6 +238,10 @@ class GlobalConfig(object):
# Allowed "trusted sources" for request
TRUSTED_SOURCES = Config.section(SECURITY_SECTION).value('Trusted Hosts', '*')
# How long will a service "in use" be allowed to exists once a new publication is launched, defaults to 3 days
# This is expressed in hours
KEEP_IN_USE_HOURS = Config.section(GLOBAL_SECTION).value('Keep In Use Hours', '72')
initDone = False
@staticmethod

View File

@ -52,7 +52,7 @@ class PublicationInfoItemsCleaner(Job):
super(PublicationInfoItemsCleaner,self).__init__(environment)
def run(self):
removeFrom = getSqlDatetime() - timedelta(seconds = GlobalConfig.KEEP_INFO_TIME.getInt())
removeFrom = getSqlDatetime() - timedelta(seconds = GlobalConfig.KEEP_INFO_TIME.getInt(True))
DeployedServicePublication.objects.filter(state__in=State.INFO_STATES, state_date__lt=removeFrom).delete()
class PublicationCleaner(Job):
@ -63,13 +63,17 @@ class PublicationCleaner(Job):
super(PublicationCleaner,self).__init__(environment)
def run(self):
removables = DeployedServicePublication.objects.filter(state=State.REMOVABLE)[0:3]
removables = DeployedServicePublication.objects.filter(state=State.REMOVABLE)
for removable in removables:
try:
PublicationManager.manager().unpublish(removable)
except PublishException: # Can say that it cant be removed right now
logger.debug('Delaying removal')
pass
# Now check too long "in use" services for all publications
now = getSqlDatetime()
removeFrom = now - timedelta(hours = GlobalConfig.KEEP_IN_USE_HOURS.getInt(True))
for dsp in removables.filter(state_date__lt=removeFrom):
dsp.deployed_service.filter(in_use=True).update(in_use=False, state_date=now)
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)

View File

@ -1006,7 +1006,7 @@ class DeployedService(models.Model):
self.setState(State.REMOVED)
def markOldDeployedServicesAsRemovables(self, activePub):
def markOldUserServicesAsRemovables(self, activePub):
'''
Used when a new publication is finished.