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(
            "PyWren v{} - Starting Knative invoker".format(__version__))
        function_invoker(message)
    else:
        logger.info(
            "PyWren v{} - Starting Knative execution".format(__version__))
        function_handler(message)

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

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

    return {"Execution": "Finished"}
Example #3
0
def main(event, context):
    logger.info("Starting AWS Lambda Function execution")
    os.environ['__PW_ACTIVATION_ID'] = context.aws_request_id
    if 'remote_invoker' in event:
        logger.info("PyWren v{} - Starting invoker".format(__version__))
        function_invoker(event)
    else:
        logger.info("PyWren v{} - Starting execution".format(__version__))
        function_handler(event)

    return {"Execution": "Finished"}
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("Pywren v{} - Starting invoker".format(__version__))
        function_invoker(args)
    else:
        logger.info("Pywren v{} - Starting execution".format(__version__))
        function_handler(args)

    return {"Execution": "Finished"}
    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
Example #6
0
def main(event, context):
    logger.info("Starting GCP Functions function execution")
    # TODO: Check if GCP has its own activation ID
    act_id = str(uuid.uuid4()).replace('-', '')[:12]
    os.environ['__PW_ACTIVATION_ID'] = act_id
    args = json.loads(base64.b64decode(event['data']).decode('utf-8'))

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

    return 'OK'
Example #7
0
    def _local_handler(self, event, original_dir):
        """
        Handler to run local functions.
        """
        current_run_dir = os.path.join(self.logs_dir, event['executor_id'],
                                       event['job_id'])
        os.makedirs(current_run_dir, exist_ok=True)
        os.chdir(current_run_dir)
        old_stdout = sys.stdout
        sys.stdout = open('{}.log'.format(event['call_id']), '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)

        os.chdir(original_dir)
        sys.stdout = old_stdout
Example #8
0
import logging
from pywren_ibm_cloud.utils import version_str
from pywren_ibm_cloud.config import cloud_logging_config
from pywren_ibm_cloud.function import function_handler

cloud_logging_config(logging.INFO)
logger = logging.getLogger('__main__')


if __name__ == "__main__":

    cmd = sys.argv[1]

    if cmd == 'run':
        try:
            payload_file = sys.argv[2]
            with open(payload_file, "r") as f:
                json_payload = f.read()
            payload = json.loads(json_payload)
            function_handler(payload)
        except Exception as e:
            raise(e)
    elif cmd == 'metadata':
        runtime_meta = dict()
        mods = list(pkgutil.iter_modules())
        runtime_meta["preinstalls"] = [entry for entry in sorted([[mod, is_pkg] for _, mod, is_pkg in mods])]
        runtime_meta["python_ver"] = version_str(sys.version_info)
        print(json.dumps(runtime_meta))
    else:
        raise ValueError("Command not valid: {}", cmd)