Use exc_info

This commit is contained in:
Nuno Campos
2024-08-15 15:23:54 -07:00
parent d15c5a46de
commit 78781b0a90
2 changed files with 8 additions and 6 deletions
+4 -5
View File
@@ -3,7 +3,6 @@ import logging
import random import random
import time import time
from typing import Optional from typing import Optional
import traceback
from langgraph.pregel.types import PregelExecutableTask, RetryPolicy from langgraph.pregel.types import PregelExecutableTask, RetryPolicy
@@ -50,9 +49,8 @@ def run_with_retry(
) )
# log the retry # log the retry
logger.info( logger.info(
f"Retrying task {task.name} after {interval:.2f} seconds (attempt {attempts}) due to:\n" f"Retrying task {task.name} after {interval:.2f} seconds (attempt {attempts}) after {exc.__class__.__name__} {exc}",
f"{exc.__class__.__name__}: {exc}\n" exc_info=exc,
f"{traceback.format_exc()}"
) )
@@ -101,5 +99,6 @@ async def arun_with_retry(
) )
# log the retry # log the retry
logger.info( logger.info(
f"Retrying task {task.name} after {interval:.2f} seconds (attempt {attempts}) after {exc.__class__.__name__} {exc}" f"Retrying task {task.name} after {interval:.2f} seconds (attempt {attempts}) after {exc.__class__.__name__} {exc}",
exc_info=exc,
) )
+4 -1
View File
@@ -1,4 +1,5 @@
import json import json
import logging
import operator import operator
import time import time
import warnings import warnings
@@ -1191,7 +1192,8 @@ def test_invoke_two_processes_two_in_two_out_valid(mocker: MockerFixture) -> Non
assert app.invoke(2) == [3, 3] assert app.invoke(2) == [3, 3]
def test_invoke_checkpoint(mocker: MockerFixture) -> None: def test_invoke_checkpoint(mocker: MockerFixture, caplog) -> None:
caplog.set_level(logging.INFO)
add_one = mocker.Mock(side_effect=lambda x: x["total"] + x["input"]) add_one = mocker.Mock(side_effect=lambda x: x["total"] + x["input"])
errored_once = False errored_once = False
@@ -1236,6 +1238,7 @@ def test_invoke_checkpoint(mocker: MockerFixture) -> None:
assert checkpoint["channel_values"].get("total") == 2 assert checkpoint["channel_values"].get("total") == 2
# total is now 2, so output is 2+3=5 # total is now 2, so output is 2+3=5
assert app.invoke(3, {"configurable": {"thread_id": "1"}}) == 5 assert app.invoke(3, {"configurable": {"thread_id": "1"}}) == 5
assert 0
assert errored_once, "errored and retried" assert errored_once, "errored and retried"
checkpoint = memory.get({"configurable": {"thread_id": "1"}}) checkpoint = memory.get({"configurable": {"thread_id": "1"}})
assert checkpoint is not None assert checkpoint is not None