def test_build_graph_get_leaf_collect(self): x = AsyncResult("1") x.backend._cache["1"] = {"status": states.SUCCESS, "result": None} c = [EagerResult(str(i), i, states.SUCCESS) for i in range(3)] x.iterdeps = Mock() x.iterdeps.return_value = ((None, x), (x, c[0]), (c[0], c[1]), (c[1], c[2])) x.backend.READY_STATES = states.READY_STATES self.assertTrue(x.graph) self.assertIs(x.get_leaf(), 2) it = x.collect() self.assertListEqual(list(it), [(x, None), (c[0], 0), (c[1], 1), (c[2], 2)])
def receive(self, text_data): text_data_json = json.loads(text_data) message = text_data_json['message'] print(message) result = AsyncResult(message) while True: print(result.status) if result.ready(): if result.status == "FAILURE": logger.error(result.collect().__next__()[1]) res = "Lỗi không xác định" else: res = result.collect().__next__()[1] async_to_sync(self.channel_layer.group_send)( self.room_group_name, { 'type': 'chat_message', 'message': res, } ) break else: time.sleep(3)
def test_build_graph_get_leaf_collect(self): x = AsyncResult('1') x.backend._cache['1'] = {'status': states.SUCCESS, 'result': None} c = [EagerResult(str(i), i, states.SUCCESS) for i in range(3)] x.iterdeps = Mock() x.iterdeps.return_value = ((None, x), (x, c[0]), (c[0], c[1]), (c[1], c[2])) x.backend.READY_STATES = states.READY_STATES self.assertTrue(x.graph) self.assertIs(x.get_leaf(), 2) it = x.collect() self.assertListEqual(list(it), [ (x, None), (c[0], 0), (c[1], 1), (c[2], 2), ])
def get_result(request, task_id): res = AsyncResult(task_id) response = res.collect() for a, v in response: return JsonResponse(v, status=200)