Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Eastwood
c2e15ef26b Add changelog 2025-09-29 13:58:11 -05:00
Eric Eastwood
cd65573b07 Switch task scheduler from set_current_context -> PreserveLoggingContext
Prefer the utils over raw logcontext manipulation
2025-09-29 13:52:56 -05:00
2 changed files with 3 additions and 5 deletions

1
changelog.d/18990.misc Normal file
View File

@@ -0,0 +1 @@
Switch task scheduler from raw logcontext manipulation to using the dedicated logcontext utils.

View File

@@ -27,8 +27,8 @@ from twisted.python.failure import Failure
from synapse.logging.context import (
ContextResourceUsage,
LoggingContext,
PreserveLoggingContext,
nested_logging_context,
set_current_context,
)
from synapse.metrics import SERVER_NAME_LABEL, LaterGauge
from synapse.metrics.background_process_metrics import (
@@ -425,14 +425,11 @@ class TaskScheduler:
"""
current_time = self._clock.time()
calling_context = set_current_context(task_log_context)
try:
with PreserveLoggingContext(task_log_context):
usage = task_log_context.get_resource_usage()
TaskScheduler._log_task_usage(
"continuing", task, usage, current_time - start_time
)
finally:
set_current_context(calling_context)
async def wrapper() -> None:
with nested_logging_context(task.id) as log_context: