Skip to content

Commit 7310621

Browse files
fix: async iter
1 parent 2395f18 commit 7310621

File tree

1 file changed

+15
-0
lines changed
  • packages/celery-library/src/celery_library

1 file changed

+15
-0
lines changed

packages/celery-library/src/celery_library/errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import base64
22
import pickle
3+
from functools import wraps
4+
from inspect import isasyncgenfunction
35

46
from celery.exceptions import CeleryError # type: ignore[import-untyped]
57
from common_library.errors_classes import OsparcErrorMixin
@@ -42,6 +44,19 @@ class InternalError(OsparcErrorMixin, Exception):
4244

4345

4446
def handle_celery_errors(func):
47+
if isasyncgenfunction(func):
48+
49+
@wraps(func)
50+
async def async_generator_wrapper(*args, **kwargs):
51+
try:
52+
async for item in func(*args, **kwargs):
53+
yield item
54+
except CeleryError as exc:
55+
raise InternalError from exc
56+
57+
return async_generator_wrapper
58+
59+
@wraps(func)
4560
async def wrapper(*args, **kwargs):
4661
try:
4762
return await func(*args, **kwargs)

0 commit comments

Comments
 (0)