def publish(self, servicePool, changeLog=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) ''' 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')) try: now = getSqlDatetime() dsp = None dsp = 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) DelayedTaskRunner.runner().insert(PublicationLauncher(dsp), 4, PUBTAG + str(dsp.id)) except Exception as e: logger.debug('Caught exception at publish: {0}'.format(e)) if dsp is not None: try: dsp.delete() except Exception: logger.info('Could not delete {}'.format(dsp)) raise PublishException(str(e))
def checkLater(servicePoolPub, pi): ''' Inserts a task in the delayedTaskRunner so we can check the state of this publication @param dps: Database object for DeployedServicePublication @param pi: Instance of Publication manager for the object ''' DelayedTaskRunner.runner().insert(PublicationFinishChecker(servicePoolPub), pi.suggestedTime, PUBTAG + str(servicePoolPub.id))
def publish(self, servicePool): # 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) ''' 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' )) try: now = getSqlDatetime() dsp = None dsp = servicePool.publications.create( state=State.LAUNCHING, state_date=now, publish_date=now, revision=servicePool.current_pub_revision) DelayedTaskRunner.runner().insert(PublicationLauncher(dsp), 4, PUBTAG + str(dsp.id)) except Exception as e: logger.debug('Caught exception at publish: {0}'.format(e)) if dsp is not None: try: dsp.delete() except Exception: logger.info('Could not delete {}'.format(dsp)) raise PublishException(str(e))
def makeUnique(userService, userServiceInstance, state): ''' 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 DeployedServicePublication @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 checkLater(userService, userServiceInstance): """ Inserts a task in the delayedTaskRunner so we can check the state of this migration @param userService: Database object for DeployedServicePublication @param userServiceInstance: Instance of Publication manager for the object """ from uds.core.jobs.DelayedTaskRunner import DelayedTaskRunner # Do not add task if already exists one that updates this service if DelayedTaskRunner.runner().checkExists(MIGRATETASK_TAG + str(userService.id)): return DelayedTaskRunner.runner().insert(ClusterUpdateStats(userService), userServiceInstance.suggestedTime, ClusterUpdateStats + str(userService.id))
def makeUnique(userService, userServiceInstance, state): """ 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 notifyTermination(self): DelayedTaskRunner.runner().notifyTermination()
def run(self): DelayedTaskRunner.runner().run()