本文整理汇总了Python中WMCore.Database.CMSCouch.Document.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python Document.setdefault方法的具体用法?Python Document.setdefault怎么用?Python Document.setdefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Database.CMSCouch.Document
的用法示例。
在下文中一共展示了Document.setdefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recordTaskActivity
# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import setdefault [as 别名]
def recordTaskActivity(self, taskname, comment = ''):
"""Record a task for monitoring"""
try:
record = self.db.document('task_activity')
except CouchNotFoundError:
record = Document('task_activity')
record.setdefault('tasks', {})
record['tasks'].setdefault(taskname, {})
record['tasks'][taskname]['timestamp'] = time.time()
record['tasks'][taskname]['comment'] = comment
try:
self.db.commitOne(record)
except StandardError, ex:
self.logger.error("Unable to update task %s freshness: %s" % (taskname, str(ex)))
示例2: recordTaskActivity
# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import setdefault [as 别名]
def recordTaskActivity(self, taskname, comment=""):
"""Record a task for monitoring"""
try:
record = self.db.document("task_activity")
except CouchNotFoundError:
record = Document("task_activity")
record.setdefault("tasks", {})
record["tasks"].setdefault(taskname, {})
record["tasks"][taskname]["timestamp"] = time.time()
record["tasks"][taskname]["comment"] = comment
try:
self.db.commitOne(record)
except Exception as ex:
self.logger.error("Unable to update task %s freshness: %s" % (taskname, str(ex)))
示例3: CouchWorkQueueElement
# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import setdefault [as 别名]
class CouchWorkQueueElement(WorkQueueElement):
"""
_CouchWorkQueueElement_
"""
def __init__(self, couchDB, id = None, elementParams = None):
elementParams = elementParams or {}
WorkQueueElement.__init__(self, **elementParams)
if id:
self._id = id
self._document = Document(id = id)
self._couch = couchDB
rev = property(
lambda x: str(x._document[u'_rev']) if x._document.has_key(u'_rev') else x._document.__getitem__('_rev'),
lambda x, newid: x._document.__setitem__('_rev', newid))
timestamp = property(
lambda x: str(x._document[u'timestamp']) if x._document.has_key(u'timestamp') else x._document.__getitem__('timestamp')
)
updatetime = property(
lambda x: str(x._document[u'updatetime']) if x._document.has_key(u'updatetime') else 0
)
@classmethod
def fromDocument(cls, couchDB, doc):
"""Create element from couch document"""
element = CouchWorkQueueElement(couchDB = couchDB,
id = doc['_id'],
elementParams = doc.pop('WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement')
)
element._document['_rev'] = doc.pop('_rev')
element._document['timestamp'] = doc.pop('timestamp')
element._document['updatetime'] = doc.pop('updatetime')
return element
def save(self):
"""
_save
"""
self.populateDocument()
self._couch.queue(self._document)
def load(self):
"""
_load_
Load the document representing this WQE
"""
document = self._couch.document(self._document['_id'])
self.update(document.pop('WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement'))
self._document['_rev'] = document.pop('_rev')
self._document['timestamp'] = document.pop('timestamp', None)
self._document['updatetime'] = document.pop('updatetime', None)
return self
def delete(self):
"""Delete element"""
self.populateDocument()
self._document.delete()
self._couch.queue(self._document)
def populateDocument(self):
"""Certain attributed shouldn't be stored"""
self._document.update(self.__to_json__(None))
now = time.time()
self._document['updatetime'] = now
self._document.setdefault('timestamp', now)
if not self._document.get('_id') and self.id:
self._document['_id'] = self.id
attrs = ['WMSpec', 'Task']
for attr in attrs:
self._document['WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement'].pop(attr, None)