diff --git a/server/src/uds/core/managers/PublicationManager.py b/server/src/uds/core/managers/PublicationManager.py index 5e708719..26292ce2 100644 --- a/server/src/uds/core/managers/PublicationManager.py +++ b/server/src/uds/core/managers/PublicationManager.py @@ -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 diff --git a/server/src/uds/core/util/Config.py b/server/src/uds/core/util/Config.py index 5b7034b0..cd73b65e 100644 --- a/server/src/uds/core/util/Config.py +++ b/server/src/uds/core/util/Config.py @@ -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 diff --git a/server/src/uds/core/workers/PublicationCleaner.py b/server/src/uds/core/workers/PublicationCleaner.py index c68fe13b..a14a1f17 100644 --- a/server/src/uds/core/workers/PublicationCleaner.py +++ b/server/src/uds/core/workers/PublicationCleaner.py @@ -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 - - - \ No newline at end of file + # 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) + diff --git a/server/src/uds/models.py b/server/src/uds/models.py index 8bc0b49a..e6d5df49 100644 --- a/server/src/uds/models.py +++ b/server/src/uds/models.py @@ -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.