示例#1
0
def main(args):
    if 'remote_invoker' in args:
        logger.info("Starting IBM Cloud Functions invoker")
        function_invoker(args)
    else:
        logger.info("Starting IBM Cloud Functions execution")
        function_handler(args)

    return {"Execution": "Finished"}
示例#2
0
    def _local_handler(self, event, original_dir):
        """
        Handler to run local functions.
        """
        current_run_dir = os.path.join(LOCAL_RUN_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']['LOCAL_EXECUTION'] = 'True'
        function_handler(event)

        os.chdir(original_dir)
        sys.stdout = old_stdout
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]
    logger.info("Starting knative Function execution")
    function_handler(message)
    response = flask.jsonify({"activationId": act_id})
    response.status_code = 202

    return complete(response)
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()

    logger.info("Starting knative Function execution")
    function_handler(message)
    result = {"Execution": "Finished"}
    response = flask.jsonify(result)
    response.status_code = 202

    return complete(response)
示例#5
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['__OW_ACTIVATION_ID'] = act_id

    if 'remote_invoker' in message:
        logger.info("Starting Knative invoker")
        function_invoker(message)
    else:
        logger.info("Starting Knative execution")
        function_handler(message)

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

    return complete(response)
示例#6
0
def main(args):
    logger.info("Starting IBM Cloud Functions execution")
    function_handler(args)
    return {"Execution": "Finished"}
示例#7
0
from pywren_ibm_cloud.utils import version_str
from pywren_ibm_cloud.config import cloud_logging_config
from pywren_ibm_cloud.runtime.function_handler 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)