Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions langfuse/_task_manager/media_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,29 @@ def _process_upload_media_job(
def _request_with_backoff(
self, func: Callable[P, T], *args: P.args, **kwargs: P.kwargs
) -> T:
@backoff.on_exception(
backoff.expo, Exception, max_tries=self._max_retries, logger=None
)
def execute_task_with_backoff() -> T:
try:
return func(*args, **kwargs)
except ApiError as e:
if (
def _should_give_up(e: Exception) -> bool:
if isinstance(e, ApiError):
return (
e.status_code is not None
and 400 <= e.status_code < 500
and (e.status_code) != 429
):
raise e
except Exception as e:
raise e
and e.status_code != 429
)
if isinstance(e, requests.exceptions.RequestException):
return (
e.response is not None
and e.response.status_code < 500
and e.response.status_code != 429
)
return False

raise Exception("Failed to execute task")
@backoff.on_exception(
backoff.expo,
Exception,
max_tries=self._max_retries,
giveup=_should_give_up,
logger=None,
)
def execute_task_with_backoff() -> T:
return func(*args, **kwargs)

return execute_task_with_backoff()
Loading