def checkAndUpdateState(publication: ServicePoolPublication, publicationInstance: 'services.Publication', state: str) -> None: """ Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object Return True if it has to continue checking, False if finished """ try: prevState: str = publication.state checkLater: bool = False if State.isFinished(state): # Now we mark, if it exists, the previous usable publication as "Removable" if State.isPreparing(prevState): old: ServicePoolPublication for old in publication.deployed_service.publications.filter( state=State.USABLE): old.setState(State.REMOVABLE) osm = publication.deployed_service.osmanager # If os manager says "machine is persistent", do not tray to delete "previous version" assigned machines doPublicationCleanup = True if osm is None else not osm.getInstance( ).isPersistent() if doPublicationCleanup: pc = PublicationOldMachinesCleaner(old.id) pc.register( GlobalConfig.SESSION_EXPIRE_TIME.getInt(True) * 3600, 'pclean-' + str(old.id), True) publication.deployed_service.markOldUserServicesAsRemovables( publication) else: # Remove only cache services, not assigned publication.deployed_service.markOldUserServicesAsRemovables( publication, True) publication.setState(State.USABLE) elif State.isRemoving(prevState): publication.setState(State.REMOVED) else: # State is canceling publication.setState(State.CANCELED) # Mark all previous publications deployed services as removables # and make this usable publicationInstance.finish() publication.updateData(publicationInstance) elif State.isErrored(state): publication.updateData(publicationInstance) publication.setState(State.ERROR) else: checkLater = True # The task is running publication.updateData(publicationInstance) if checkLater: PublicationFinishChecker.checkLater(publication, publicationInstance) except Exception: logger.exception('At checkAndUpdate for publication') PublicationFinishChecker.checkLater(publication, publicationInstance)
def getItems(self, parent: models.ServicePool, item: typing.Optional[str]): return [{ 'id': i.uuid, 'revision': i.revision, 'publish_date': i.publish_date, 'state': i.state, 'reason': State.isErrored(i.state) and i.getInstance().reasonOfError() or '', 'state_date': i.state_date, } for i in parent.publications.all()]