mirror of
https://github.com/element-hq/synapse.git
synced 2026-06-05 21:01:37 +00:00
Port Clock functions to use Duration class (#19229)
This changes the arguments in clock functions to be `Duration` and converts call sites and constants into `Duration`. There are still some more functions around that should be converted (e.g. `timeout_deferred`), but we leave that to another PR. We also changes `.as_secs()` to return a float, as the rounding broke things subtly. The only reason to keep it (its the same as `timedelta.total_seconds()`) is for symmetry with `as_millis()`. Follows on from https://github.com/element-hq/synapse/pull/19223
This commit is contained in:
@@ -158,6 +158,7 @@ from synapse.types.state import StateFilter
|
||||
from synapse.util.async_helpers import maybe_awaitable
|
||||
from synapse.util.caches.descriptors import CachedFunction, cached as _cached
|
||||
from synapse.util.clock import Clock
|
||||
from synapse.util.duration import Duration
|
||||
from synapse.util.frozenutils import freeze
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -1389,7 +1390,7 @@ class ModuleApi:
|
||||
if self._hs.config.worker.run_background_tasks or run_on_all_instances:
|
||||
self._clock.looping_call(
|
||||
self._hs.run_as_background_process,
|
||||
msec,
|
||||
Duration(milliseconds=msec),
|
||||
desc,
|
||||
lambda: maybe_awaitable(f(*args, **kwargs)),
|
||||
)
|
||||
@@ -1444,8 +1445,7 @@ class ModuleApi:
|
||||
desc = f.__name__
|
||||
|
||||
return self._clock.call_later(
|
||||
# convert ms to seconds as needed by call_later.
|
||||
msec * 0.001,
|
||||
Duration(milliseconds=msec),
|
||||
self._hs.run_as_background_process,
|
||||
desc,
|
||||
lambda: maybe_awaitable(f(*args, **kwargs)),
|
||||
@@ -1457,7 +1457,7 @@ class ModuleApi:
|
||||
Added in Synapse v1.49.0.
|
||||
"""
|
||||
|
||||
await self._clock.sleep(seconds)
|
||||
await self._clock.sleep(Duration(seconds=seconds))
|
||||
|
||||
async def send_http_push_notification(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user