Beispiel #1
0
def test_code_to_snapshot_and_from_snapshot(default_os_env):
    code1 = Code(add2)
    snapshot1 = code1.to_snapshot(args=(1, 2))
    code2 = Code.from_snapshot(snapshot=snapshot1)
    assert code2.get_state() == 'UNKNOWN'
    assert code2(1, 2) == 3
Beispiel #2
0
async def run_by_snapshot(params: SnapshotJSON):
    snapshot = CodeSnapshot.from_json(params.snapshot)
    code = Code.from_snapshot(snapshot)
    common.supervisor.run_code(code=code, args=snapshot.args, kwargs=snapshot.kwargs)
    return {'serial_number': code.serial_number}
def load_and_run_code_from_snapshot(snapshot):
    code = Code.from_snapshot(snapshot)
    code(*snapshot['args'], **snapshot['kwargs'])
Beispiel #4
0
        '-p',
        '--path',
        help='path to the directory including callback functions')
    parser.add_argument('-l', '--logger', help='a logger name to write logs')
    args = parser.parse_args()
    if args.logger:
        logger = Default.get_logger(args.logger)
        sys.stdout.write = partial(Worker.log, logger.info)
    else:
        logger = None
    try:
        callback_storage = FileStorage(item_type=Callback,
                                       path=args.path if args.path else '.')
        callback_service = CallbackService(storage=callback_storage)
        code_snapshot = CodeSnapshot.from_file(args.snapshot)
        code_args = code_snapshot.args
        code_kwargs = code_snapshot.kwargs
        code = Code.from_snapshot(code_snapshot)
        if args.callback:
            callbacks = list()
            for name in args.callback:
                cb = callback_service.pull(name)
                callbacks.append(cb)
            code.register_callback(callbacks)
        code(*code_args, **code_kwargs)
    except Exception as e:
        if logger:
            logger.error(e)
        else:
            print(e)
def load_and_run_code_from_snapshot_and_raise_exception(snapshot):
    code = Code.from_snapshot(snapshot)
    code(*snapshot['args'], **snapshot['kwargs'])
    raise KeyboardInterrupt