Пример #1
0
 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
0
 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
0
 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)))
Пример #4
0
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)
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 u'_rev' in x._document else x._document.__getitem__('_rev'),
        lambda x, newid: x._document.__setitem__('_rev', newid))
    timestamp = property(lambda x: str(x._document[u'timestamp'])
                         if u'timestamp' in x._document else x._document.
                         __getitem__('timestamp'))
    updatetime = property(lambda x: str(x._document[u'updatetime'])
                          if u'updatetime' in x._document else 0)

    @classmethod
    def fromDocument(cls, couchDB, doc):
        """Create element from couch document"""
        elementParams = doc.pop(
            'WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement')
        elementParams["CreationTime"] = doc.pop('timestamp')
        element = CouchWorkQueueElement(couchDB=couchDB,
                                        id=doc['_id'],
                                        elementParams=elementParams)
        element._document['_rev'] = doc.pop('_rev')
        element._document['timestamp'] = elementParams["CreationTime"]
        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)