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)
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"}
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 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'
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) sys.stdout = open(log_file, 'w') 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: try: logger.info( "PyWren v{} - Starting Docker invoker".format(__version__)) message['config']['pywren']['remote_invoker'] = False message['config']['pywren']['compute_backend'] = 'localhost' if 'localhost' not in message['config']: message['config']['localhost'] = {} if message['config']['pywren']['workers'] is None: total_cpus = multiprocessing.cpu_count() message['config']['pywren']['workers'] = total_cpus message['config']['localhost']['workers'] = total_cpus else: message['config']['localhost']['workers'] = message['config'][ 'pywren']['workers'] message['invokers'] = 0 message['log_level'] = None function_invoker(message) except Exception as e: logger.info(e) response = flask.jsonify({"activationId": act_id}) response.status_code = 202 return complete(response)