def publish(self, servicePool: ServicePool, changeLog: typing.Optional[str] = None): # pylint: disable=no-self-use """ Initiates the publication of a service pool, or raises an exception if this cannot be done :param servicePool: Service pool object (db object) :param changeLog: if not None, store change log string on "change log" table """ if servicePool.publications.filter(state__in=State.PUBLISH_STATES).count() > 0: raise PublishException(_('Already publishing. Wait for previous publication to finish and try again')) if servicePool.isInMaintenance(): raise PublishException(_('Service is in maintenance mode and new publications are not allowed')) publication: typing.Optional[ServicePoolPublication] = None try: now = getSqlDatetime() publication = servicePool.publications.create(state=State.LAUNCHING, state_date=now, publish_date=now, revision=servicePool.current_pub_revision) if changeLog: servicePool.changelog.create(revision=servicePool.current_pub_revision, log=changeLog, stamp=now) if publication: DelayedTaskRunner.runner().insert(PublicationLauncher(publication), 4, PUBTAG + str(publication.id)) except Exception as e: logger.debug('Caught exception at publish: %s', e) if publication is not None: try: publication.delete() except Exception: logger.info('Could not delete %s', publication) raise PublishException(str(e))
def checkLater(publication: ServicePoolPublication, publicationInstance: 'services.Publication'): """ Inserts a task in the delayedTaskRunner so we can check the state of this publication @param dps: Database object for ServicePoolPublication @param pi: Instance of Publication manager for the object """ DelayedTaskRunner.runner().insert(PublicationFinishChecker(publication), publicationInstance.suggestedTime, PUBTAG + str(publication.id))
def makeUnique(userService: UserService, userServiceInstance: UserDeployment, state: str): """ This method ensures that there will be only one delayedtask related to the userService indicated """ DelayedTaskRunner.runner().remove(USERSERVICE_TAG + userService.uuid) UserServiceOpChecker.checkAndUpdateState(userService, userServiceInstance, state)
def checkLater(userService, ci): """ Inserts a task in the delayedTaskRunner so we can check the state of this publication @param dps: Database object for ServicePoolPublication @param pi: Instance of Publication manager for the object """ # Do not add task if already exists one that updates this service if DelayedTaskRunner.runner().checkExists(USERSERVICE_TAG + userService.uuid): return DelayedTaskRunner.runner().insert(UserServiceOpChecker(userService), ci.suggestedTime, USERSERVICE_TAG + userService.uuid)
def notifyTermination(self): DelayedTaskRunner.runner().notifyTermination()
def run(self): DelayedTaskRunner.runner().run()