Fix bug with new task scheduler using lots of CPU. (#16278)
Using the new `TaskScheduler` meant that we'ed create lots of new metrics (due to adding task ID to the desc of background process), resulting in requests for metrics taking an increasing amount of CPU.pull/15979/head
parent
9084429a6c
commit
f43d994624
|
@ -0,0 +1 @@
|
|||
Fix using the new task scheduler causing lots of CPU to be used.
|
|
@ -19,6 +19,7 @@ from prometheus_client import Gauge
|
|||
|
||||
from twisted.python.failure import Failure
|
||||
|
||||
from synapse.logging.context import nested_logging_context
|
||||
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||
from synapse.types import JsonMapping, ScheduledTask, TaskStatus
|
||||
from synapse.util.stringutils import random_string
|
||||
|
@ -316,6 +317,7 @@ class TaskScheduler:
|
|||
function = self._actions[task.action]
|
||||
|
||||
async def wrapper() -> None:
|
||||
with nested_logging_context(task.id):
|
||||
try:
|
||||
(status, result, error) = await function(task)
|
||||
except Exception:
|
||||
|
@ -353,5 +355,4 @@ class TaskScheduler:
|
|||
|
||||
self._running_tasks.add(task.id)
|
||||
await self.update_task(task.id, status=TaskStatus.ACTIVE)
|
||||
description = f"{task.id}-{task.action}"
|
||||
run_as_background_process(description, wrapper)
|
||||
run_as_background_process(task.action, wrapper)
|
||||
|
|
Loading…
Reference in New Issue