コード例 #1
0
ファイル: decorators.py プロジェクト: AgentK1729/insights
        def run(func=None, *args, **kw):
            """ Executes the function decorated by @cron

                This function can be called from two distinct places. It can be
                called by the task scheduler (due to @periodic_task),
                in which case func will be None.

                It can also be called as a result of calling the function we
                are currently decorating with @cron. In this case func will be
                the same as f.
            """

            # Was it called from the task scheduler?
            called_as_periodic = True if func is None else False

            if called_as_periodic:
                if force_memoize:
                    func = use_forcememoize(f)
                else:
                    func = f
            else:
                func = f

            result = optional_parameter_call(func, params)

            return result
コード例 #2
0
ファイル: decorators.py プロジェクト: olabi/insights
        def run(func=None, *args, **kw):
            """ Executes the function decorated by @cron

                This function can be called from two distinct places. It can be
                called by the task scheduler (due to @periodic_task),
                in which case func will be None.

                It can also be called as a result of calling the function we
                are currently decorating with @cron. In this case func will be
                the same as f.
            """

            # Was it called from the task scheduler?
            called_as_periodic = True if func is None else False

            if called_as_periodic:
                if force_memoize:
                    func = use_forcememoize(f)
                else:
                    func = f
            else:
                func = f

            result = optional_parameter_call(func, params)

            return result
コード例 #3
0
def handle_event(sender, **kwargs):
    ''' Receives either an event or a list of events, as sent by
    djeventstream (either from a Python logging HTTPHandler or
    SNSHandler. 

    Forwards it along to the event handlers defined in the modules. 

    This is not a view, but it is the moral equivalent. 
    '''
    # Handle strings, lists, and dictionaries
    # TODO handle errors if not valid json
    msg = kwargs['msg']
    if isinstance(msg,str) or isinstance(msg,unicode):
        msg = json.loads(msg)

    # If we get a batch of events, we need to load them. 
    if isinstance(msg,list):
        for i in xrange(0,len(msg)):
            try:
                msg[i] = json.loads(msg[i])
            except:
                pass

    # Single event should still be passed as a list for API 
    # compatibility between patched and unbatched. 
    if not isinstance(msg, list):
        msg = [msg]
    
    from registry import StreamingEvent
    msg = map(StreamingEvent, msg)

    for e in event_handlers:
        event_func = e['function']
        batch = e['batch']
        if not batch: ## Message was a list of events, but handler cannot batch events
            for event in msg:
                try:
                    optional_parameter_call(event_func, {'events':[event]})
                except:
                    handle_event_exception(e['function'])
        else: ## Message was a list of events, and handler can batch events
            try:
                optional_parameter_call(event_func, {'events':msg})
            except:
                handle_event_exception(e['function'])

    return HttpResponse( "Success" )
コード例 #4
0
ファイル: registry.py プロジェクト: olabi/insights
def handle_request(cls, name, **kwargs):
    ''' Generic code to handle views and requests '''
    args = dict()
    categories = request_handlers[cls]
    if name in categories:
        handler_dict = categories[name]
    else:
        raise Http404(name + "  is not a valid function")
    handler = handler_dict['function']
    if 'args' in handler_dict:
        arglist = handler_dict['arglist']
    else:
        arglist = inspect.getargspec(handler).args

    from util import optional_parameter_call
    return optional_parameter_call(handler, kwargs, arglist)
コード例 #5
0
ファイル: registry.py プロジェクト: avontd2868/ed-insights
def handle_request(cls, name, **kwargs):
    ''' Generic code to handle views and requests '''
    args = dict()
    categories = request_handlers[cls]
    if name in categories: 
        handler_dict = categories[name]
    else:
        raise Http404(name+"  is not a valid function")
    handler = handler_dict['function']
    if 'args' in handler_dict:
        arglist = handler_dict['arglist']
    else:
        arglist = inspect.getargspec(handler).args

    from util import optional_parameter_call, default_optional_kwargs
    return optional_parameter_call(handler, default_optional_kwargs, kwargs, arglist)