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

Python func.utc_timestamp函数代码示例

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

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



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

示例1: persistOperation

  def persistOperation(self, operation):
    """ update or insert request into db
        Also release the assignment tag

    :param operation: FTS3Operation instance
    """

    session = self.dbSession(expire_on_commit=False)

    # set the assignment to NULL
    # so that another agent can work on the request
    operation.assignment = None
    # because of the merge we have to explicitely set lastUpdate
    operation.lastUpdate = func.utc_timestamp()
    try:

      # Merge it in case it already is in the DB
      operation = session.merge(operation)
      session.add(operation)
      session.commit()
      session.expunge_all()

      return S_OK(operation.operationID)

    except SQLAlchemyError as e:
      session.rollback()
      self.log.exception("persistOperation: unexpected exception", lException=e)
      return S_ERROR("persistOperation: unexpected exception %s" % e)
    finally:
      session.close()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:30,代码来源:FTS3DB.py


示例2: kickStuckJobs

  def kickStuckJobs(self, limit=20, kickDelay=2):
    """finds jobs that have not been updated for more than a given
      time but are still assigned and resets the assignment

    :param int limit: number of jobs to treat
    :param int kickDelay: age of the lastUpdate in hours
    :returns: S_OK/S_ERROR with number of kicked jobs

    """

    session = self.dbSession(expire_on_commit=False)

    try:

      ftsJobs = session.query(FTS3Job.jobID)\
          .filter(FTS3Job.lastUpdate < (func.date_sub(func.utc_timestamp(),
                                                      text('INTERVAL %d HOUR' % kickDelay
                                                           ))))\
          .filter(~FTS3Job.assignment.is_(None))\
          .limit(limit)

      jobIDs = [jobTuple[0] for jobTuple in ftsJobs]
      rowCount = 0

      if jobIDs:
        result = session.execute(
            update(FTS3Job) .where(
                FTS3Job.jobID.in_(jobIDs)) .where(
                FTS3Job.lastUpdate < (
                    func.date_sub(
                        func.utc_timestamp(), text(
                            'INTERVAL %d HOUR' %
                            kickDelay)))) .values(
                {
                    'assignment': None}))
        rowCount = result.rowcount

      session.commit()
      session.expunge_all()

      return S_OK(rowCount)

    except SQLAlchemyError as e:
      session.rollback()
      return S_ERROR("kickStuckJobs: unexpected exception : %s" % e)
    finally:
      session.close()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:47,代码来源:FTS3DB.py


示例3: define_tables

    def define_tables(cls, metadata):
        Table(
            "t",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("x", Integer),
            Column("data", DateTime),
        )

        Table(
            "t_default",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("x", Integer),
            Column("idata", DateTime, default=func.utc_timestamp()),
            Column("udata", DateTime, onupdate=func.utc_timestamp()),
        )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:17,代码来源:test_dialect.py


示例4: clearOldNotifications

def clearOldNotifications(conn):
    """Clear old notifications

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.base.Connection
  """
    delete = schema.notification.delete().where(  # pylint: disable=E1120
        func.date_add(schema.notification.c.timestamp, text("INTERVAL 30 DAY")) < func.utc_timestamp()
    )
    conn.execute(delete)
开发者ID:darreldonnelly,项目名称:numenta-apps,代码行数:10,代码来源:queries.py


示例5: deleteStaleNotificationDevices

def deleteStaleNotificationDevices(conn, days):
  """Deletes devices from notifications if they haven't been active recently.

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.base.Connection
  :param days: the number of days of absense before considering a device stale
  :type days: int
  """
  query = schema.notification_settings.delete().where(  # pylint: disable=E1120
      func.date_add(schema.notification_settings.c.last_timestamp,
                    text("INTERVAL %i DAY" % days)) <
      func.utc_timestamp())
  conn.execute(query)
开发者ID:bertdg,项目名称:numenta-apps,代码行数:13,代码来源:queries.py


示例6: updateJobStatus

  def updateJobStatus(self, jobStatusDict):
    """ Update the job Status and error
        The update is only done if the job is not in a final state
        The assignment flag is released

       :param jobStatusDict : { jobID : { status , error, completeness } }
    """
    session = self.dbSession()
    try:

      for jobID, valueDict in jobStatusDict.iteritems():

        updateDict = {FTS3Job.status: valueDict['status']}

        # We only update error if it is specified
        if 'error' in valueDict:
          newError = valueDict['error']
          # Replace empty string with None
          if not newError:
            newError = None
          updateDict[FTS3Job.error] = newError

        if 'completeness' in valueDict:
          updateDict[FTS3Job.completeness] = valueDict['completeness']

        if valueDict.get('lastMonitor'):
          updateDict[FTS3Job.lastMonitor] = func.utc_timestamp()

        updateDict[FTS3Job.assignment] = None

        session.execute(update(FTS3Job)
                        .where(and_(FTS3Job.jobID == jobID,
                                    ~ FTS3Job.status.in_(FTS3Job.FINAL_STATES)
                                    )
                               )
                        .values(updateDict)
                        )
      session.commit()

      return S_OK()

    except SQLAlchemyError as e:
      session.rollback()
      self.log.exception("updateJobStatus: unexpected exception", lException=e)
      return S_ERROR("updateJobStatus: unexpected exception %s" % e)
    finally:
      session.close()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:47,代码来源:FTS3DB.py


示例7: updateNotificationDeviceTimestamp

def updateNotificationDeviceTimestamp(conn, deviceId):
  """Updates last access timestamp for the specified device.

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.base.Connection
  :param deviceId: Device uid
  :type deviceId: str
  :raises: ObjectNotFoundError when there is no device with deviceId configured
  """
  query = (schema.notification_settings
           .update()
           .where(schema.notification_settings.c.uid == deviceId)
           .values(last_timestamp=func.utc_timestamp()))
  result = conn.execute(query)
  if result.rowcount == 0:
    raise ObjectNotFoundError("No notification settings for device: %s" %
                              deviceId)
开发者ID:bertdg,项目名称:numenta-apps,代码行数:17,代码来源:queries.py


示例8: test_update_executemany_w_default

    def test_update_executemany_w_default(self):
        with testing.db.connect() as conn:
            timestamp = datetime.datetime(2015, 4, 17, 18, 5, 2)
            conn.execute(
                self.tables.t_default.insert(),
                [
                    {"x": 5, "idata": timestamp},
                    {"x": 6, "idata": timestamp},
                    {"x": 7, "idata": timestamp},
                ],
            )

            conn.execute(
                self.tables.t_default.update()
                .values(idata=func.utc_timestamp())
                .where(self.tables.t_default.c.x == bindparam("xval")),
                [{"xval": 5}, {"xval": 6}, {"xval": 7}],
            )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:18,代码来源:test_dialect.py


示例9: _getCloudwatchMetricReadinessPredicate

def _getCloudwatchMetricReadinessPredicate(conn):
  """ Generate an sqlAlchemy predicate that determines whether the metric is
  ready for data collection.

  :returns: sqlAlchemy predicate for use in `where` clause
  """
  # NOTE: the time arithmetic must be coordinated with
  # grok.app.aws.cloudwatch_utils.getMetricCollectionBackoffSeconds()

  # NOTE: the time difference logic here is a heuristic fine-tuned for
  # cloudwatch-based metrics as follows:
  #   * Cloudwatch metrics aggregated over a specific period (e.g., 5 minutes)
  #     appear to be arranged in contiguous time buckets each with a specific
  #     start and end time; we don't have visibility into the actual start time
  #     of any bucket, which appears to depend on when the cloudwatch metric was
  #     created.
  #   * In the higher-level logic, the first time we query a metric, we pick the
  #     metric's virtual starting time based on a 14-day backoff from current
  #     time (which is not the actual metric time bucket's start time) and
  #     subsequently add the metric's period to arrive at the next metric
  #     value's virtual start time, and so on.
  #   * Based on experiments with 5-minute-aggregated metrics, it appears that a
  #     metric's aggregated value becomes availabe one period after the true end
  #     of the metric value's time bucket. If you don't wait long enough, you
  #     either don't get any value from cloudwatch (which is a wasted slow call
  #     that contributes to API throttling) or you might get a non-final
  #     value.
  #   * Since we don't know the true start time of the time bucket, we
  #     compensate for it: first, we add the metric period to the virtual start
  #     time, which should get us at least to the end of the true time bucket;
  #     then we add another period to get us at least to the point in time where
  #     the time-bucket's data becomes available, and finally add a fudge value
  #     (60 seconds at time of this writing) for the metric value to stabilize
  return (
    (schema.metric.c.last_timestamp == None)
    | (func.timestampdiff(text("SECOND"),
                          schema.metric.c.last_timestamp,
                          func.utc_timestamp())
       >= (schema.metric.c.poll_interval +
           (schema.metric.c.poll_interval + 60))))
开发者ID:bertdg,项目名称:numenta-apps,代码行数:40,代码来源:queries.py


示例10: deleteFinalOperations

  def deleteFinalOperations(self, limit=20, deleteDelay=180):
    """deletes operation in final state that are older than given time

    :param int limit: number of operations to treat
    :param int deleteDelay: age of the lastUpdate in days
    :returns: S_OK/S_ERROR with number of deleted operations
    """

    session = self.dbSession(expire_on_commit=False)

    try:

      ftsOps = session.query(
          FTS3Operation.operationID) .filter(
          FTS3Operation.lastUpdate < (
              func.date_sub(
                  func.utc_timestamp(),
                  text(
                      'INTERVAL %d DAY' %
                      deleteDelay)))) .filter(
          FTS3Operation.status.in_(
              FTS3Operation.FINAL_STATES)) .limit(limit)

      opIDs = [opTuple[0] for opTuple in ftsOps]
      rowCount = 0
      if opIDs:
        result = session.execute(delete(FTS3Operation)
                                 .where(FTS3Operation.operationID.in_(opIDs)))
        rowCount = result.rowcount

      session.commit()
      session.expunge_all()

      return S_OK(rowCount)

    except SQLAlchemyError as e:
      session.rollback()
      return S_ERROR("deleteFinalOperations: unexpected exception : %s" % e)
    finally:
      session.close()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:40,代码来源:FTS3DB.py


示例11: is_stuck

 def is_stuck(self, mins=10):
     diff = func.timestampdiff(text('minute'),
                               self.updated_at, func.utc_timestamp())
     return (self.updated_at == None) | (diff > mins)
开发者ID:Dipsomaniac,项目名称:graphite-alerts,代码行数:4,代码来源:orm.py


示例12: MetaData

from DIRAC.DataManagementSystem.Client.FTS3Job import FTS3Job
from DIRAC.ConfigurationSystem.Client.Utilities import getDBParameters

__RCSID__ = "$Id$"


metadata = MetaData()


fts3FileTable = Table('Files', metadata,
                      Column('fileID', Integer, primary_key=True),
                      Column('operationID', Integer,
                             ForeignKey('Operations.operationID', ondelete='CASCADE'),
                             nullable=False),
                      Column('attempt', Integer, server_default='0'),
                      Column('lastUpdate', DateTime, onupdate=func.utc_timestamp()),
                      Column('rmsFileID', Integer, server_default='0'),
                      Column('lfn', String(1024)),
                      Column('checksum', String(255)),
                      Column('size', BigInteger),
                      Column('targetSE', String(255), nullable=False),
                      Column('error', String(2048)),
                      Column('ftsGUID', String(255)),
                      Column('status', Enum(*FTS3File.ALL_STATES),
                             server_default=FTS3File.INIT_STATE,
                             index=True),
                      mysql_engine='InnoDB',
                      )

mapper(FTS3File, fts3FileTable)
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:30,代码来源:FTS3DB.py


示例13: test_utc_timestamp

 def test_utc_timestamp(self):
     self.assert_compile(func.utc_timestamp(), "UTC_TIMESTAMP")
开发者ID:robin900,项目名称:sqlalchemy,代码行数:2,代码来源:test_compiler.py


示例14: test_utc_timestamp_fsp

 def test_utc_timestamp_fsp(self):
     self.assert_compile(
         func.utc_timestamp(5), "utc_timestamp(%s)",
         checkparams={"utc_timestamp_1": 5})
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:4,代码来源:test_compiler.py


示例15: Table

        )

    annotation_types = Table('annotation_types', meta,
        Column('annotation_type_id', Integer, primary_key=True),
        Column('name', String(255), nullable=False),
        UniqueConstraint('name', name='uc_annotation_type_name')
        )


    annotations = Table('annotations', meta,
        Column('annotation_id', Integer, primary_key=True),
        Column('document_id', Integer, nullable=False),
        Column('annotation_type_id', Integer, nullable=False),
        Column('identifier_id', Integer, nullable=False),
        Column('creator_id', Integer, nullable=False),
        Column('created_ts', DateTime(timezone=True), default=func.utc_timestamp()),
        Column('comment', Text, nullable=False),
        ForeignKeyConstraint(['document_id'], ['documents.document_id']),
        ForeignKeyConstraint(['annotation_type_id'], ['annotation_types.annotation_type_id']),
        ForeignKeyConstraint(['identifier_id'], ['identifiers.identifier_id']),
        ForeignKeyConstraint(['creator_id'], ['creators.creator_id']),
        )


    scanners = Table('scanners', meta,
        Column('scanner_id', Integer, primary_key=True),
        Column('name', String(255), nullable=False),
        UniqueConstraint('name', name='uc_scanner_name')
        )

    packages_scans = Table('packages_scans', meta,
开发者ID:axnasim,项目名称:CSCI4900-1,代码行数:31,代码来源:schema.updated.py


示例16: create_engine

#!/usr/bin/env python
# -*- coding:utf8 -*-

from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Date
from sqlalchemy.types import TypeDecorator
from sqlalchemy import DateTime
import time

from sqlalchemy import func
from sqlalchemy.sql.expression import select, text

dsn = "mysql://xxxxx:[email protected]/xxxxx?charset=utf8"
engine = create_engine(dsn, convert_unicode=True, echo=False)
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

if __name__ == "__main__":

    r = db_session.execute(select([(func.utc_timestamp() - text("INTERVAL 2 DAY"))])).first()
    print r[0].strftime("%Y/%m/%d %H:%I:%S")

    # func => SQLの関数
    # text => SQLの文
开发者ID:tell-k,项目名称:code-snippets,代码行数:29,代码来源:execute_test.py


示例17: test_insert_executemany

 def test_insert_executemany(self):
     with testing.db.connect() as conn:
         conn.execute(
             self.tables.t.insert().values(data=func.utc_timestamp()),
             [{"x": 5}, {"x": 6}, {"x": 7}],
         )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:6,代码来源:test_dialect.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python inspection.inspect函数代码示例发布时间:2022-05-27
下一篇:
Python func.upper函数代码示例发布时间: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