Skip to content

Commit b590079

Browse files
authored
Merge branch 'master' into enh/integrate-book-a-call
2 parents 596e938 + e04c848 commit b590079

File tree

91 files changed

+309
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+309
-247
lines changed

.github/workflows/cleanup-caches-by-branches.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ on:
88
jobs:
99
cleanup:
1010
runs-on: ubuntu-latest
11+
permissions:
12+
actions: write
1113
steps:
1214
- name: Cleanup
1315
run: |
14-
gh extension install actions/gh-actions-cache
15-
16-
echo "Fetching list of cache key"
17-
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
16+
echo "Fetching list of cache keys"
17+
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
1818
1919
## Setting this to not fail the workflow while deleting cache keys.
2020
set +e
2121
echo "Deleting caches..."
2222
for cacheKey in $cacheKeysForPR
2323
do
24-
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
24+
gh cache delete $cacheKey
2525
done
2626
echo "Done"
2727
env:
28-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
REPO: ${{ github.repository }}
28+
GH_TOKEN: ${{ github.token }}
29+
GH_REPO: ${{ github.repository }}
3030
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

packages/common-library/src/common_library/async_tools.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
import datetime
33
import functools
44
import logging
5+
import sys
56
from collections.abc import Awaitable, Callable, Coroutine
67
from concurrent.futures import Executor
78
from functools import wraps
89
from inspect import isawaitable
910
from typing import Any, ParamSpec, TypeVar, overload
1011

12+
from .logging.logging_errors import create_troubleshooting_log_kwargs
13+
1114
_logger = logging.getLogger(__name__)
1215

1316
R = TypeVar("R")
@@ -102,11 +105,13 @@ async def cancel_wait_task(
102105
# from observing the cancellation/finalization of task.
103106
asyncio.wait_for(task, timeout=max_delay)
104107
)
105-
except TimeoutError:
108+
except TimeoutError as exc:
106109
_logger.exception(
107-
"Timeout while cancelling task %s after %s seconds",
108-
task.get_name(),
109-
max_delay,
110+
**create_troubleshooting_log_kwargs(
111+
f"Timeout while cancelling task {task.get_name()} after {max_delay} seconds",
112+
error=exc,
113+
error_context={"task_name": task.get_name(), "max_delay": max_delay},
114+
)
110115
)
111116
raise
112117
except asyncio.CancelledError:
@@ -117,7 +122,20 @@ async def cancel_wait_task(
117122
raise
118123
finally:
119124
if not task.done():
120-
_logger.error("Failed to cancel %s", task.get_name())
125+
current_exception = sys.exception()
126+
_logger.error(
127+
**create_troubleshooting_log_kwargs(
128+
f"Failed to cancel ask {task.get_name()}",
129+
error=(
130+
current_exception if current_exception else Exception("Unknown")
131+
),
132+
error_context={
133+
"task_name": task.get_name(),
134+
"max_delay": max_delay,
135+
},
136+
tip="Consider increasing max_delay or fixing the task to handle cancellations properly",
137+
)
138+
)
121139
else:
122140
_logger.debug("Task %s cancelled", task.get_name())
123141

packages/common-library/src/common_library/logging/__init__.py

Whitespace-only changes.

packages/service-library/src/servicelib/logging_errors.py renamed to packages/common-library/src/common_library/logging/logging_errors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any, TypedDict
2+
from typing import Any, Final, TypedDict
33

44
from common_library.error_codes import ErrorCodeStr
55
from common_library.errors_classes import OsparcErrorMixin
@@ -9,6 +9,8 @@
99

1010
_logger = logging.getLogger(__name__)
1111

12+
_MAX_LOGGED_CAUSES: Final[int] = 10
13+
1214

1315
def create_troubleshooting_log_message(
1416
user_error_msg: str,
@@ -36,7 +38,7 @@ def _collect_causes(exc: BaseException) -> str:
3638
seen.add(id(current))
3739
causes.append(f"[{type(current).__name__}]'{current}'")
3840
current = getattr(current, "__cause__", None)
39-
if len(causes) > 10: # Prevent excessive chains
41+
if len(causes) > _MAX_LOGGED_CAUSES: # Prevent excessive chains
4042
causes.append("[... truncated]")
4143
break
4244
return " <- ".join(causes)

packages/service-library/tests/test_logging_errors.py renamed to packages/common-library/tests/test_logging_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from common_library.error_codes import create_error_code, parse_error_code_parts
77
from common_library.errors_classes import OsparcErrorMixin
8-
from servicelib.logging_errors import (
8+
from common_library.logging.logging_errors import (
99
create_troubleshooting_log_kwargs,
1010
create_troubleshooting_log_message,
1111
)

packages/service-library/tests/test_logging_utils_filtering.py renamed to packages/common-library/tests/test_logging_utils_filtering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# pylint: disable=redefined-outer-name
22

33
import logging
4-
from typing import Generator
4+
from collections.abc import Generator
55

66
import pytest
7-
from servicelib.logging_utils_filtering import GeneralLogFilter
7+
from common_library.logging.logging_utils_filtering import GeneralLogFilter
88

99

1010
@pytest.fixture

packages/service-library/src/servicelib/aiohttp/rest_middlewares.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from aiohttp.web_response import StreamResponse
1414
from common_library.error_codes import ErrorCodeStr, create_error_code
1515
from common_library.json_serialization import json_dumps, json_loads
16+
from common_library.logging.logging_errors import create_troubleshooting_log_kwargs
1617
from common_library.user_messages import user_message
1718
from models_library.basic_types import IDStr
1819
from models_library.rest_error import ErrorGet, ErrorItemType, LogMessageType
1920

20-
from ..logging_errors import create_troubleshooting_log_kwargs
2121
from ..mimetype_constants import MIMETYPE_APPLICATION_JSON
2222
from ..rest_constants import RESPONSE_MODEL_POLICY
2323
from ..rest_responses import is_enveloped_from_text
@@ -202,7 +202,6 @@ def _handle_exception_as_http_error(
202202

203203

204204
def error_middleware_factory(api_version: str) -> Middleware:
205-
206205
@web.middleware
207206
async def _middleware_handler(request: web.Request, handler: Handler):
208207
"""

packages/service-library/src/servicelib/exception_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
from functools import wraps
66
from typing import Any, Final, ParamSpec, TypeVar
77

8+
from common_library.logging.logging_errors import create_troubleshooting_log_kwargs
89
from pydantic import BaseModel, Field, NonNegativeFloat, PrivateAttr
910

10-
from .logging_errors import create_troubleshooting_log_kwargs
11-
1211
_logger = logging.getLogger(__name__)
1312

1413
_SKIPS_MESSAGE: Final[str] = "skip(s) of exception"

0 commit comments

Comments
 (0)