Beispiel #1
0
def dispatcher(request):
    function_request = json.loads(b64decode(request.body.decode()).decode())
    try:
        execute_function(function_request)
        return {}
    except Exception as e:
        logger.error('Failure running function', exc_info=True)
        raise BadRequest(e)
Beispiel #2
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    if getattr(settings, 'BEANSTALK_DISPATCH_EXECUTE_SYNCHRONOUSLY', False):
        execute_function(json.loads(body))
    else:
        connection = boto.connect_sqs(settings.BEANSTALK_DISPATCH_SQS_KEY,
                                      settings.BEANSTALK_DISPATCH_SQS_SECRET)
        queue = connection.get_queue(queue_name)
        if not queue:
            queue = connection.create_queue(queue_name)
        message = boto.sqs.message.Message()
        message.set_body(body)
        queue.write(message)
Beispiel #3
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    if getattr(settings, 'BEANSTALK_DISPATCH_EXECUTE_SYNCHRONOUSLY', False):
        execute_function(json.loads(body))
    else:
        connection = boto.connect_sqs(
            settings.BEANSTALK_DISPATCH_SQS_KEY,
            settings.BEANSTALK_DISPATCH_SQS_SECRET)
        queue = connection.get_queue(queue_name)
        if not queue:
            queue = connection.create_queue(queue_name)
        message = boto.sqs.message.Message()
        message.set_body(body)
        queue.write(message)