mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Convert runWithConnection to async. (#8121)
This commit is contained in:
parent
d294f0e7e1
commit
d89692ea84
1
changelog.d/8121.misc
Normal file
1
changelog.d/8121.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Convert various parts of the codebase to async/await.
|
@ -175,7 +175,7 @@ def run_as_background_process(desc: str, func, *args, **kwargs):
|
|||||||
It returns a Deferred which completes when the function completes, but it doesn't
|
It returns a Deferred which completes when the function completes, but it doesn't
|
||||||
follow the synapse logcontext rules, which makes it appropriate for passing to
|
follow the synapse logcontext rules, which makes it appropriate for passing to
|
||||||
clock.looping_call and friends (or for firing-and-forgetting in the middle of a
|
clock.looping_call and friends (or for firing-and-forgetting in the middle of a
|
||||||
normal synapse inlineCallbacks function).
|
normal synapse async function).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
desc: a description for this background process type
|
desc: a description for this background process type
|
||||||
|
@ -516,7 +516,8 @@ class DatabasePool(object):
|
|||||||
logger.warning("Starting db txn '%s' from sentinel context", desc)
|
logger.warning("Starting db txn '%s' from sentinel context", desc)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = yield self.runWithConnection(
|
result = yield defer.ensureDeferred(
|
||||||
|
self.runWithConnection(
|
||||||
self.new_transaction,
|
self.new_transaction,
|
||||||
desc,
|
desc,
|
||||||
after_callbacks,
|
after_callbacks,
|
||||||
@ -525,6 +526,7 @@ class DatabasePool(object):
|
|||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
for after_callback, after_args, after_kwargs in after_callbacks:
|
for after_callback, after_args, after_kwargs in after_callbacks:
|
||||||
after_callback(*after_args, **after_kwargs)
|
after_callback(*after_args, **after_kwargs)
|
||||||
@ -535,8 +537,7 @@ class DatabasePool(object):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def runWithConnection(self, func: Callable, *args: Any, **kwargs: Any) -> Any:
|
||||||
def runWithConnection(self, func: Callable, *args: Any, **kwargs: Any):
|
|
||||||
"""Wraps the .runWithConnection() method on the underlying db_pool.
|
"""Wraps the .runWithConnection() method on the underlying db_pool.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -547,7 +548,7 @@ class DatabasePool(object):
|
|||||||
kwargs: named args to pass to `func`
|
kwargs: named args to pass to `func`
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: The result of func
|
The result of func
|
||||||
"""
|
"""
|
||||||
parent_context = current_context() # type: Optional[LoggingContextOrSentinel]
|
parent_context = current_context() # type: Optional[LoggingContextOrSentinel]
|
||||||
if not parent_context:
|
if not parent_context:
|
||||||
@ -570,12 +571,10 @@ class DatabasePool(object):
|
|||||||
|
|
||||||
return func(conn, *args, **kwargs)
|
return func(conn, *args, **kwargs)
|
||||||
|
|
||||||
result = yield make_deferred_yieldable(
|
return await make_deferred_yieldable(
|
||||||
self._db_pool.runWithConnection(inner_func, *args, **kwargs)
|
self._db_pool.runWithConnection(inner_func, *args, **kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cursor_to_dict(cursor):
|
def cursor_to_dict(cursor):
|
||||||
"""Converts a SQL cursor into an list of dicts.
|
"""Converts a SQL cursor into an list of dicts.
|
||||||
|
Loading…
Reference in New Issue
Block a user