def test_save_restore(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = GroupResult(uuid(), subs) ts.save() with self.assertRaises(AttributeError): ts.save(backend=object()) self.assertEqual(GroupResult.restore(ts.id).subtasks, ts.subtasks) ts.delete() self.assertIsNone(GroupResult.restore(ts.id))
def test_empty_group_result(self, manager): if not manager.app.conf.result_backend.startswith('redis'): raise pytest.skip('Requires redis result backend.') task = group([]) result = task.apply_async() GroupResult.save(result) task = GroupResult.restore(result.id) assert task.results == []
def test_groupresult_save_restore(self): """Test if we can save and restore a GroupResult""" group_id = uuid() results = [AsyncResult(id=uuid())] group = GroupResult(id=group_id, results=results) group.save(backend=self.b) restored_group = self.b.restore_group(group_id=group_id) assert restored_group == group
def create_group_result(self): """Return a GroupResult model instance with a single, successful result""" id = uuid() task_result = self.create_task_result() task_result.status = states.SUCCESS task_result.save() results = [AsyncResult(id=task_result.task_id)] group = CeleryGroupResult(id=id, results=results) group.save() meta = GroupResult.objects.get(group_id=id) return meta
def test_groupresult_save_restore_nested(self): """Test if we can save and restore a nested GroupResult""" group_id = uuid() async_result = AsyncResult(id=uuid()) nested_results = [AsyncResult(id=uuid()), AsyncResult(id=uuid())] nested_group = GroupResult(id=uuid(), results=nested_results) group = GroupResult(id=group_id, results=[nested_group, async_result]) group.save(backend=self.b) restored_group = self.b.restore_group(group_id=group_id) assert restored_group == group
def post(self): task_ids = request.form.getlist('task_ids') results = [AsyncResult(tid, app=app.celery) for tid in task_ids] group_result = GroupResult(id=str(uuid.uuid4()), results=results) group_result.save() successful = all_finished(group_result.results) return { 'status': 'SUCCESS' if successful else 'PENDING', 'bulk_task_id': str(group_result.id), 'bulk_task_url': app.api.url_for(TaskSubscriptionAPI, bulk_task_id=str(group_result.id), _external=True), 'task_results': get_all_task_results(group_result.results) }