Exemplo n.º 1
0
def run():
    def error():
        response = flask.jsonify({
            'error':
            'The action did not receive a dictionary as an argument.'
        })
        response.status_code = 404
        return complete(response)

    message = flask.request.get_json(force=True, silent=True)
    if message and not isinstance(message, dict):
        return error()

    act_id = str(uuid.uuid4()).replace('-', '')[:12]
    os.environ['__PW_ACTIVATION_ID'] = act_id

    if 'remote_invoker' in message:
        logger.info(
            "Cloudbutton v{} - Starting Knative invoker".format(__version__))
        function_invoker(message)
    else:
        logger.info(
            "Cloudbutton v{} - Starting Knative execution".format(__version__))
        function_handler(message)

    response = flask.jsonify({"activationId": act_id})
    response.status_code = 202

    return complete(response)
Exemplo n.º 2
0
def main(args):
    os.environ['__PW_ACTIVATION_ID'] = os.environ['__OW_ACTIVATION_ID']
    if 'remote_invoker' in args:
        logger.info("Cloudbutton v{} - Starting invoker".format(__version__))
        function_invoker(args)
    else:
        logger.info("Cloudbutton v{} - Starting execution".format(__version__))
        function_handler(args)

    return {"Execution": "Finished"}
Exemplo n.º 3
0
def main(event, context):
    args = json.loads(event)
    os.environ['__PW_ACTIVATION_ID'] = context.request_id
    if 'remote_invoker' in args:
        logger.info("Cloudbutton v{} - Starting invoker".format(__version__))
        function_invoker(args)
    else:
        logger.info("Cloudbutton v{} - Starting execution".format(__version__))
        function_handler(args)

    return {"Execution": "Finished"}
Exemplo n.º 4
0
    def _local_handler(self, event):
        """
        Handler to run local functions.
        """
        if not self.log_level:
            old_stdout = sys.stdout
            sys.stdout = open(os.devnull, 'w')

        event['extra_env']['__PW_LOCAL_EXECUTION'] = 'True'
        act_id = str(uuid.uuid4()).replace('-', '')[:12]
        os.environ['__PW_ACTIVATION_ID'] = act_id
        function_handler(event)

        if not self.log_level:
            sys.stdout = old_stdout
Exemplo n.º 5
0
def main(msgIn: func.QueueMessage):
    try:
        args = json.loads(msgIn.get_body())
    except:        
        args = msgIn.get_json()

    os.environ['__PW_ACTIVATION_ID'] = str(msgIn.id)
    if 'remote_invoker' in args:
        logger.info("Cloudbutton v{} - Starting invoker".format(__version__))
        function_invoker(args)
    else:
        logger.info("Cloudbutton v{} - Starting execution".format(__version__))
        function_handler(args)

    return {"Execution": "Finished"}