def test_pack_data(): data = {'x': 1} assert pack_data(('x', 'y'), data) == (1, 'y') data = {b'x': 1} assert pack_data((b'x', 'y'), data) == (1, 'y') assert pack_data({'a': b'x', 'b': 'y'}, data) == {'a': 1, 'b': 'y'} assert pack_data({'a': [b'x'], 'b': 'y'}, data) == {'a': [1], 'b': 'y'}
def test_pack_data(): data = {'x': 1} assert pack_data(('x', 'y'), data) == (1, 'y') data = {b'x': 1} assert pack_data((b'x', 'y'), data) == (1, 'y') assert pack_data({'a': b'x', 'b': 'y'}, data) == {'a': 1, 'b': 'y'} assert pack_data({'a': [b'x'], 'b': 'y'}, data) == {'a': [1], 'b': 'y'}
async def _prepare_raw_components(self, raw_components): """ Take raw components and resolve future dependencies. """ function, args, kwargs, deps = raw_components futures = self.client._graph_to_futures({}, deps) data = await self.client._gather(futures) args = pack_data(args, data) kwargs = pack_data(kwargs, data) return (function, args, kwargs)
def transition(self, key, start, finish, *args, **kwargs): if finish in status_finish: function_name, emit_id, _ = key.split('--') ts = self.worker.tasks[key] exc = ts.exception trace = ts.traceback trace = traceback.format_tb(trace.data) error = str(exc.data) if 'SerializedTask' in str(type(ts.runspec)): function = loads(ts.runspec.function) args = ts.runspec.args args = loads(args) if args else () kwargs = ts.runspec.kwargs kwargs = loads(kwargs) if kwargs else () else: function, args, kwargs = ts.runspec function_name = f'{function.__module__}.{function.__name__}' data = {} for dep in ts.dependencies: try: data[dep.key] = self.worker.data[dep.key] except BaseException: pass args2 = pack_data(args, data, key_types=(bytes, str)) kwargs2 = pack_data(kwargs, data, key_types=(bytes, str)) data = { 'function': function_name, 'args': args2, 'kwargs': kwargs2, 'exception': trace, 'error': error, 'key': key, 'emit_id': emit_id } self.persist(data, datetime.now())
def test_pack_data(): data = {"x": 1} assert pack_data(("x", "y"), data) == (1, "y") assert pack_data({"a": "x", "b": "y"}, data) == {"a": 1, "b": "y"} assert pack_data({"a": ["x"], "b": "y"}, data) == {"a": [1], "b": "y"}