Ejemplo n.º 1
0
 def watch_execution_time(self, obj, prefix=''):
     classname = utils.classname(obj)
     members = dir(obj)
     for name in members:
         value = getattr(obj, name)
         if not name.startswith('_') and hasattr(value, '__call__'):
             statsd_key = "%s.%s.%s" % (prefix, classname, name)
             decorated_method = self.timer(statsd_key)(value)
             setattr(obj, name, decorated_method)
Ejemplo n.º 2
0
 def watch_execution_time(self, obj, prefix='', classname=None):
     classname = classname or utils.classname(obj)
     members = dir(obj)
     for name in members:
         value = getattr(obj, name)
         is_method = isinstance(value, types.MethodType)
         if not name.startswith('_') and is_method:
             statsd_key = "%s.%s.%s" % (prefix, classname, name)
             decorated_method = self.timer(statsd_key)(value)
             setattr(obj, name, decorated_method)
Ejemplo n.º 3
0
    def __init__(self, request, context=None):
        # Models are isolated by user.
        parent_id = self.get_parent_id(request)

        # Authentication to storage is transmitted as is (cf. cloud_storage).
        auth = request.headers.get('Authorization')

        self.model = self.default_model(
            storage=request.registry.storage,
            id_generator=request.registry.id_generator,
            collection_id=classname(self),
            parent_id=parent_id,
            auth=auth)

        self.request = request
        self.context = context
        self.record_id = self.request.matchdict.get('id')
        self.force_patch_update = False

        # Log resource context.
        logger.bind(collection_id=self.model.collection_id,
                    collection_timestamp=self.timestamp)
Ejemplo n.º 4
0
    def __init__(self, request, context):
        # Collections are isolated by user.
        parent_id = context.prefixed_userid

        # Authentication to storage is transmitted as is (cf. cloud_storage).
        auth = request.headers.get('Authorization')

        self.collection = Collection(
            storage=request.registry.storage,
            id_generator=request.registry.id_generator,
            collection_id=classname(self),
            parent_id=parent_id,
            auth=auth)

        self.request = request
        self.context = context
        self.timestamp = self.collection.timestamp()
        self.record_id = self.request.matchdict.get('id')

        # Log resource context.
        logger.bind(collection_id=self.collection.collection_id,
                    collection_timestamp=self.timestamp)
Ejemplo n.º 5
0
    def __init__(self, request, context=None):
        # Models are isolated by user.
        parent_id = self.get_parent_id(request)

        # Authentication to storage is transmitted as is (cf. cloud_storage).
        auth = request.headers.get('Authorization')

        self.model = self.default_model(
            storage=request.registry.storage,
            id_generator=request.registry.id_generator,
            collection_id=classname(self),
            parent_id=parent_id,
            auth=auth)

        self.request = request
        self.context = context
        self.record_id = self.request.matchdict.get('id')
        self.force_patch_update = False

        # Log resource context.
        logger.bind(collection_id=self.model.collection_id,
                    collection_timestamp=self.timestamp)
Ejemplo n.º 6
0
def populate_timestamps_table(session, flush_context, instances):
    for instance in session.new:
        if getattr(instance, 'is_timestamp_trackeable', False):
            timestamp = session.query(Timestamps).get([instance.parent_id, classname(instance)])
            timestamp.last_modified = datetime.datetime.utcnow()
            session.merge(timestamp)
Ejemplo n.º 7
0
 def name(self):
     """Resource name, unique."""
     return classname(self)