• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.getSqlDatetime函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中uds.models.getSqlDatetime函数的典型用法代码示例。如果您正苦于以下问题:Python getSqlDatetime函数的具体用法?Python getSqlDatetime怎么用?Python getSqlDatetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getSqlDatetime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: executeOneJob

    def executeOneJob(self):
        '''
        Looks for the best waiting job and executes it
        '''
        jobInstance = None
        try:
            now = getSqlDatetime()  # Datetimes are based on database server times
            fltr = Q(state=State.FOR_EXECUTE) & (Q(last_execution__gt=now) | Q(next_execution__lt=now))
            with transaction.atomic():
                # If next execution is before now or last execution is in the future (clock changed on this server, we take that task as executable)
                # This params are all set inside fltr (look at __init__)
                job = dbScheduler.objects.select_for_update().filter(fltr).order_by('next_execution')[0]  # @UndefinedVariable
                job.state = State.RUNNING
                job.owner_server = self._hostname
                job.last_execution = now
                job.save()

            jobInstance = job.getInstance()

            if jobInstance is None:
                logger.error('Job instance can\'t be resolved for {0}, removing it'.format(job))
                job.delete()
                return
            logger.debug('Executing job:>{0}<'.format(job.name))
            JobThread(jobInstance, job).start()  # Do not instatiate thread, just run it
        except IndexError:
            # Do nothing, there is no jobs for execution
            return
        except DatabaseError:
            # Whis will happen whenever a connection error or a deadlock error happens
            # This in fact means that we have to retry operation, and retry will happen on main loop
            # Look at this http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
            # I have got some deadlock errors, but looking at that url, i found that it is not so abnormal
            # logger.debug('Deadlock, no problem at all :-) (sounds hards, but really, no problem, will retry later :-) )')
            raise DatabaseError('Database access problems. Retrying connection')
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:35,代码来源:Scheduler.py


示例2: run

 def run(self):
     logger.debug('Publishing')
     servicePoolPub = None
     try:
         now = getSqlDatetime()
         with transaction.atomic():
             servicePoolPub = DeployedServicePublication.objects.select_for_update().get(pk=self._publishId)
             if servicePoolPub.state != State.LAUNCHING:  # If not preparing (may has been canceled by user) just return
                 return
             servicePoolPub.state = State.PREPARING
             servicePoolPub.save()
         pi = servicePoolPub.getInstance()
         state = pi.publish()
         deployedService = servicePoolPub.deployed_service
         deployedService.current_pub_revision += 1
         deployedService.storeValue('toBeReplacedIn', pickle.dumps(now + datetime.timedelta(hours=GlobalConfig.SESSION_EXPIRE_TIME.getInt(True))))
         deployedService.save()
         PublicationFinishChecker.checkAndUpdateState(servicePoolPub, pi, state)
     except DeployedServicePublication.DoesNotExist:  # Deployed service publication has been removed from database, this is ok, just ignore it
         pass
     except Exception:
         logger.exception("Exception launching publication")
         try:
             servicePoolPub.state = State.ERROR
             servicePoolPub.save()
         except Exception:
             logger.error('Error saving ERROR state for pool {}'.format(servicePoolPub))
开发者ID:dkmstr,项目名称:openuds,代码行数:27,代码来源:PublicationManager.py


示例3: _save

    def _save(self, name, content):
        name = self.get_valid_name(name)
        try:
            f = self._dbFileForReadWrite(name)
        except DBFile.DoesNotExist:
            now = getSqlDatetime()
            f = DBFile.objects.create(owner=self.owner, name=name, created=now, modified=now)

        f.data = content.read()
        f.modified = getSqlDatetime()
        f.save()

        # Store on cache also
        self._storeInCache(f)

        return name
开发者ID:glyptodon,项目名称:openuds,代码行数:16,代码来源:FileStorage.py


示例4: __log

    def __log(self, owner_type, owner_id, level, message, source, avoidDuplicates):
        """
        Logs a message associated to owner
        """
        from uds.models import getSqlDatetime
        from uds.models import Log

        # Ensure message fits on space
        message = message[:255]

        qs = Log.objects.filter(owner_id=owner_id, owner_type=owner_type)
        # First, ensure we do not have more than requested logs, and we can put one more log item
        if qs.count() >= GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt():
            for i in qs.order_by('-created',)[GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt() - 1:]:
                i.delete()

        if avoidDuplicates is True:
            try:
                lg = Log.objects.filter(owner_id=owner_id, owner_type=owner_type, level=level, source=source).order_by('-created', '-id')[0]
                if lg.message == message:
                    # Do not log again, already logged
                    return
            except Exception:  # Do not exists log
                pass

        # now, we add new log
        try:
            Log.objects.create(owner_type=owner_type, owner_id=owner_id, created=getSqlDatetime(), source=source, level=level, data=message)
        except:
            # Some objects will not get logged, such as System administrator objects
            pass
开发者ID:dkmstr,项目名称:openuds,代码行数:31,代码来源:LogManager.py


示例5: publish

    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))
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:26,代码来源:PublicationManager.py


示例6: executeOneDelayedTask

    def executeOneDelayedTask(self):
        now = getSqlDatetime()
        filt = Q(execution_time__lt=now) | Q(insert_date__gt=now + timedelta(seconds=30))
        # If next execution is before now or last execution is in the future (clock changed on this server, we take that task as executable)
        try:
            with transaction.atomic():  # Encloses
                # Throws exception if no delayed task is avilable
                task = dbDelayedTask.objects.select_for_update().filter(filt).order_by('execution_time')[0]  # @UndefinedVariable
                if task.insert_date > now + timedelta(seconds=30):
                    logger.warning('EXecuted {} due to insert_date being in the future!'.format(task.type))
                taskInstanceDump = encoders.decode(task.instance, 'base64')
                task.delete()
            taskInstance = loads(taskInstanceDump)
        except IndexError:
            return  # No problem, there is no waiting delayed task
        except Exception:
            # Transaction have been rolled back using the "with atomic", so here just return
            # Note that is taskInstance can't be loaded, this task will not be retried
            logger.exception('Executing one task')
            return

        if taskInstance is not None:
            logger.debug('Executing delayedTask:>{0}<'.format(task))
            taskInstance.env = Environment.getEnvForType(taskInstance.__class__)
            DelayedTaskThread(taskInstance).start()
开发者ID:dkmstr,项目名称:openuds,代码行数:25,代码来源:DelayedTaskRunner.py


示例7: addCounter

    def addCounter(self, owner_type, owner_id, counterType, counterValue, stamp=None):
        '''
        Adds a new counter stats to database.

        Args:

            owner_type: type of owner (integer, from internal tables)
            owner_id:  id of the owner
            counterType: The type of counter that will receive the value (look at uds.core.util.stats.counters module)
            counterValue: Counter to store. Right now, this must be an integer value (-2G ~ 2G)
            stamp: if not None, this will be used as date for cuounter, else current date/time will be get
                   (this has a granurality of seconds)

        Returns:

            Nothing
        '''
        if stamp is None:
            stamp = getSqlDatetime()

        # To Unix epoch
        stamp = int(time.mktime(stamp.timetuple()))  # pylint: disable=maybe-no-member

        try:
            StatsCounters.objects.create(owner_type=owner_type, owner_id=owner_id, counter_type=counterType, value=counterValue, stamp=stamp)
            return True
        except Exception:
            logger.error('Exception handling counter stats saving (maybe database is full?)')
        return False
开发者ID:aiminickwong,项目名称:openuds,代码行数:29,代码来源:StatsManager.py


示例8: run

 def run(self):
     """
     Look for "hanged" scheduler tasks and reset them
     """
     since = getSqlDatetime() - timedelta(minutes=15)
     with transaction.atomic():
         Scheduler.objects.select_for_update().filter(last_execution__lt=since, state=State.RUNNING).update(owner_server='', state=State.FOR_EXECUTE)
开发者ID:dkmstr,项目名称:openuds,代码行数:7,代码来源:SchedulerHouseKeeping.py


示例9: getServicesPoolsCounters

def getServicesPoolsCounters(servicePool, counter_type):
    # pylint: disable=no-value-for-parameter
    try:
        cacheKey = (servicePool and servicePool.id or 'all') + str(counter_type) + str(POINTS) + str(SINCE)
        to = getSqlDatetime()
        since = to - timedelta(days=SINCE)
        val = cache.get(cacheKey)
        if val is None:
            if servicePool is None:
                us = DeployedService()
                complete = True  # Get all deployed services stats
            else:
                us = servicePool
                complete = False
            val = []
            for x in counters.getCounters(us, counter_type, since=since, to=to, limit=POINTS, use_max=USE_MAX, all=complete):
                val.append({'stamp': x[0], 'value': int(x[1])})
            if len(val) > 2:
                cache.put(cacheKey, pickle.dumps(val).encode('zip'), 600)
            else:
                val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
        else:
            val = pickle.loads(val.decode('zip'))

        return val
    except:
        logger.exception('exception')
        raise ResponseError('can\'t create stats for objects!!!')
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:28,代码来源:system.py


示例10: get

 def get(self, rangeStart=0, rangeEnd=MAX_SEQ):
     '''
     Tries to generate a new unique id in the range provided. This unique id
     is global to "unique ids' database
     '''
     # First look for a name in the range defined
     stamp = getSqlDatetime(True)
     # logger.debug(UniqueId)
     try:
         UniqueId.objects.lock()  # @UndefinedVariable
         flt = self.__filter(rangeStart, rangeEnd)
         try:
             item = flt.filter(assigned=False).order_by('seq')[0]
             UniqueId.objects.filter(id=item.id).update(owner=self._owner, assigned=True, stamp=stamp)  # @UndefinedVariable
             seq = item.seq
         except Exception:  # No free element found
             try:
                 last = flt.filter(assigned=True)[0]  # DB Returns correct order so the 0 item is the last
                 seq = last.seq + 1
             except Exception:  # If there is no assigned at database
                 seq = rangeStart
             # logger.debug('Found seq {0}'.format(seq))
             if seq > rangeEnd:
                 return -1  # No ids free in range
             UniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp)  # @UndefinedVariable
         logger.debug('Seq: {}'.format(seq))
         return seq
     except Exception:
         logger.exception('Generating unique id sequence')
         return None
     finally:
         UniqueId.objects.unlock()  # @UndefinedVariable
开发者ID:joaoguariglia,项目名称:openuds,代码行数:32,代码来源:UniqueIDGenerator.py


示例11: releaseOlderThan

 def releaseOlderThan(self, stamp=None):
     stamp = getSqlDatetime(True) if stamp == None else stamp
     try:
         UniqueId.objects.lock()  # @UndefinedVariable
         UniqueId.objects.filter(owner=self._owner, stamp__lt=stamp).update(assigned=False, owner='', stamp=stamp)  # @UndefinedVariable
         self.__purge()
     finally:
         UniqueId.objects.unlock()  # @UndefinedVariable
开发者ID:joaoguariglia,项目名称:openuds,代码行数:8,代码来源:UniqueIDGenerator.py


示例12: __doCleanup

    def __doCleanup(self, model):
        minTime = time.mktime((getSqlDatetime() - datetime.timedelta(days=GlobalConfig.STATS_DURATION.getInt())).timetuple())

        # Newer Django versions (at least 1.7) does this deletions as it must (executes a DELETE FROM ... WHERE...)
        model.objects.filter(stamp__lt=minTime).delete()

        # Optimize mysql tables after deletions
        optimizeTable(model._meta.db_table)
开发者ID:aiminickwong,项目名称:openuds,代码行数:8,代码来源:StatsManager.py


示例13: releaseOwnShedules

 def releaseOwnShedules():
     """
     Releases all scheduleds being executed by this server
     """
     logger.debug('Releasing all owned scheduled tasks')
     with transaction.atomic():
         dbScheduler.objects.select_for_update().filter(owner_server=platform.node()).update(owner_server='')  # @UndefinedVariable
         dbScheduler.objects.select_for_update().filter(last_execution__lt=getSqlDatetime() - timedelta(minutes=15), state=State.RUNNING).update(owner_server='', state=State.FOR_EXECUTE)  # @UndefinedVariable
         dbScheduler.objects.select_for_update().filter(owner_server='').update(state=State.FOR_EXECUTE)  # @UndefinedVariable
开发者ID:glyptodon,项目名称:openuds,代码行数:9,代码来源:Scheduler.py


示例14: run

 def run(self):
     removeFrom = getSqlDatetime() - timedelta(seconds=10)  # We keep at least 10 seconds the machine before removing it, so we avoid connections errors
     removables = UserService.objects.filter(state=State.REMOVABLE, state_date__lt=removeFrom,
                                             deployed_service__service__provider__maintenance_mode=False)[0:UserServiceRemover.removeAtOnce]
     for us in removables:
         try:
             UserServiceManager.manager().remove(us)
         except Exception:
             logger.exception('Exception invoking remove user service {}'.format(us))
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:9,代码来源:UserServiceCleaner.py


示例15: release

 def release(self):
     try:
         UniqueId.objects.lock()  # @UndefinedVariable
         UniqueId.objects.filter(owner=self._owner).update(
             assigned=False, owner="", stamp=getSqlDatetime(True)
         )  # @UndefinedVariable
         self.__purge()
     finally:
         UniqueId.objects.unlock()  # @UndefinedVariable
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:9,代码来源:UniqueIDGenerator.py


示例16: get

    def get(self, rangeStart=0, rangeEnd=MAX_SEQ):
        """
        Tries to generate a new unique id in the range provided. This unique id
        is global to "unique ids' database
        """
        # First look for a name in the range defined
        stamp = getSqlDatetime(True)
        seq = rangeStart
        # logger.debug(UniqueId)
        counter = 0
        while True:
            counter += 1
            try:
                # logger.debug('Creating new seq in range {}-{}'.format(rangeStart, rangeEnd))
                with transaction.atomic():
                    flt = self.__filter(rangeStart, rangeEnd, forUpdate=True)
                    try:
                        item = flt.filter(assigned=False).order_by('seq')[0]
                        item.owner = self._owner
                        item.assigned = True
                        item.stamp = stamp
                        item.save()
                        # UniqueId.objects.filter(id=item.id).update(owner=self._owner, assigned=True, stamp=stamp)  # @UndefinedVariable
                        seq = item.seq
                        break
                    except IndexError:  # No free element found
                        item = None

                    # No item was found on first instance (already created, but freed)
                    if item is None:
                        # logger.debug('No free found, creating new one')
                        try:
                            last = flt.filter(assigned=True)[0]  # DB Returns correct order so the 0 item is the last
                            seq = last.seq + 1
                        except IndexError:  # If there is no assigned at database
                            seq = rangeStart
                        # logger.debug('Found seq {0}'.format(seq))
                        if seq > rangeEnd:
                            return -1  # No ids free in range
                        # May ocurr on some circustance that a concurrency access gives same item twice, in this case, we
                        # will get an "duplicate key error",
                        UniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp)  # @UndefinedVariable
                        break
            except OperationalError:  # Locked, may ocurr for example on sqlite. We will wait a bit
                # logger.exception('Got database locked')
                if counter % 5 == 0:
                    connection.close()
                time.sleep(1)
            except IntegrityError:  # Concurrent creation, may fail, simply retry
                pass
            except Exception:
                logger.exception('Error')
                return -1

        # logger.debug('Seq: {}'.format(seq))
        return seq
开发者ID:dkmstr,项目名称:openuds,代码行数:56,代码来源:UniqueIDGenerator.py


示例17: refresh

 def refresh(self, skey):
     # logger.debug('Refreshing key "%s" for cache "%s"' % (skey, self._owner,))
     try:
         key = self.__getKey(skey)
         c = dbCache.objects.get(pk=key)  # @UndefinedVariable
         c.created = getSqlDatetime()
         c.save()
     except dbCache.DoesNotExist:  # @UndefinedVariable
         logger.debug("Can't refresh cache key %s because it doesn't exists" % skey)
         return
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:10,代码来源:Cache.py


示例18: __createAssignedAtDbForNoPublication

 def __createAssignedAtDbForNoPublication(self, deployedService, user):
     '''
     __createCacheAtDb and __createAssignedAtDb uses a publication for create the UserService.
     There is cases where deployed services do not have publications (do not need them), so we need this method to create
     an UserService with no publications, and create them from an DeployedService
     '''
     self.__checkMaxDeployedReached(deployedService)
     now = getSqlDatetime()
     return deployedService.userServices.create(cache_level=0, state=State.PREPARING, os_state=State.PREPARING,
                                                state_date=now, creation_date=now, data='', publication=None, user=user, in_use=False)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:10,代码来源:UserServiceManager.py


示例19: __createAssignedAtDb

 def __createAssignedAtDb(self, deployedServicePublication, user):
     '''
     Private method to instatiate an assigned element at database with default state
     '''
     self.__checkMaxDeployedReached(deployedServicePublication.deployed_service)
     now = getSqlDatetime()
     return deployedServicePublication.userServices.create(cache_level=0, state=State.PREPARING, os_state=State.PREPARING,
                                                           state_date=now, creation_date=now, data='',
                                                           deployed_service=deployedServicePublication.deployed_service,
                                                           user=user, in_use=False)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:10,代码来源:UserServiceManager.py


示例20: run

 def run(self):
     since_state = getSqlDatetime() - timedelta(seconds=MAX_STUCK_TIME)
     # Filter for locating machine not ready
     for ds in DeployedService.objects.filter(service__provider__maintenance_mode=False):
         logger.debug('Searching for stuck states for {0}'.format(ds))
         # Info states are removed on UserServiceCleaner and VALID_STATES are ok, or if "hanged", checked on "HangedCleaner"
         for us in ds.userServices.filter(state_date__lt=since_state).exclude(state__in=State.INFO_STATES + State.VALID_STATES):
             logger.debug('Found stuck user service {0}'.format(us))
             log.doLog(ds, log.ERROR, 'User service {0} has been hard removed because it\'s stuck'.format(us.friendly_name))
             us.delete()
开发者ID:dkmstr,项目名称:openuds,代码行数:10,代码来源:StuckCleaner.py



注:本文中的uds.models.getSqlDatetime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Util.getSqlDatetime函数代码示例发布时间:2022-05-27
下一篇:
Python model.processUuid函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap