Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
d89692ea
Unverified
Commit
d89692ea
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert runWithConnection to async. (#8121)
parent
d294f0e7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/8121.misc
+1
-0
1 addition, 0 deletions
changelog.d/8121.misc
synapse/metrics/background_process_metrics.py
+1
-1
1 addition, 1 deletion
synapse/metrics/background_process_metrics.py
synapse/storage/database.py
+13
-14
13 additions, 14 deletions
synapse/storage/database.py
with
15 additions
and
15 deletions
changelog.d/8121.misc
0 → 100644
+
1
−
0
View file @
d89692ea
Convert various parts of the codebase to async/await.
This diff is collapsed.
Click to expand it.
synapse/metrics/background_process_metrics.py
+
1
−
1
View file @
d89692ea
...
...
@@ -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
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
normal synapse
inlineCallbacks
function).
normal synapse
async
function).
Args:
desc: a description for this background process type
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/database.py
+
13
−
14
View file @
d89692ea
...
...
@@ -516,14 +516,16 @@ class DatabasePool(object):
logger
.
warning
(
"
Starting db txn
'
%s
'
from sentinel context
"
,
desc
)
try
:
result
=
yield
self
.
runWithConnection
(
self
.
new_transaction
,
desc
,
after_callbacks
,
exception_callbacks
,
func
,
*
args
,
**
kwargs
result
=
yield
defer
.
ensureDeferred
(
self
.
runWithConnection
(
self
.
new_transaction
,
desc
,
after_callbacks
,
exception_callbacks
,
func
,
*
args
,
**
kwargs
)
)
for
after_callback
,
after_args
,
after_kwargs
in
after_callbacks
:
...
...
@@ -535,8 +537,7 @@ class DatabasePool(object):
return
result
@defer.inlineCallbacks
def
runWithConnection
(
self
,
func
:
Callable
,
*
args
:
Any
,
**
kwargs
:
Any
):
async
def
runWithConnection
(
self
,
func
:
Callable
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
Any
:
"""
Wraps the .runWithConnection() method on the underlying db_pool.
Arguments:
...
...
@@ -547,7 +548,7 @@ class DatabasePool(object):
kwargs: named args to pass to `func`
Returns:
Deferred:
The result of func
The result of func
"""
parent_context
=
current_context
()
# type: Optional[LoggingContextOrSentinel]
if
not
parent_context
:
...
...
@@ -570,12 +571,10 @@ class DatabasePool(object):
return
func
(
conn
,
*
args
,
**
kwargs
)
re
sult
=
yield
make_deferred_yieldable
(
re
turn
await
make_deferred_yieldable
(
self
.
_db_pool
.
runWithConnection
(
inner_func
,
*
args
,
**
kwargs
)
)
return
result
@staticmethod
def
cursor_to_dict
(
cursor
):
"""
Converts a SQL cursor into an list of dicts.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment