Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit d250521

Browse files
authored
Convert the main methods run by the reactor to async. (#8213)
1 parent abeab96 commit d250521

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

changelog.d/8213.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert various parts of the codebase to async/await.

synapse/app/admin_cmd.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def start_listening(self, listeners):
7979
pass
8080

8181

82-
@defer.inlineCallbacks
83-
def export_data_command(hs, args):
82+
async def export_data_command(hs, args):
8483
"""Export data for a user.
8584
8685
Args:
@@ -91,10 +90,8 @@ def export_data_command(hs, args):
9190
user_id = args.user_id
9291
directory = args.output_directory
9392

94-
res = yield defer.ensureDeferred(
95-
hs.get_handlers().admin_handler.export_user_data(
96-
user_id, FileExfiltrationWriter(user_id, directory=directory)
97-
)
93+
res = await hs.get_handlers().admin_handler.export_user_data(
94+
user_id, FileExfiltrationWriter(user_id, directory=directory)
9895
)
9996
print(res)
10097

@@ -232,14 +229,15 @@ def start(config_options):
232229
# We also make sure that `_base.start` gets run before we actually run the
233230
# command.
234231

235-
@defer.inlineCallbacks
236-
def run(_reactor):
232+
async def run():
237233
with LoggingContext("command"):
238-
yield _base.start(ss, [])
239-
yield args.func(ss, args)
234+
_base.start(ss, [])
235+
await args.func(ss, args)
240236

241237
_base.start_worker_reactor(
242-
"synapse-admin-cmd", config, run_command=lambda: task.react(run)
238+
"synapse-admin-cmd",
239+
config,
240+
run_command=lambda: task.react(lambda _reactor: defer.ensureDeferred(run())),
243241
)
244242

245243

synapse/app/homeserver.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,24 @@ async def do_acme() -> bool:
411411

412412
return provision
413413

414-
@defer.inlineCallbacks
415-
def reprovision_acme():
414+
async def reprovision_acme():
416415
"""
417416
Provision a certificate from ACME, if required, and reload the TLS
418417
certificate if it's renewed.
419418
"""
420-
reprovisioned = yield defer.ensureDeferred(do_acme())
419+
reprovisioned = await do_acme()
421420
if reprovisioned:
422421
_base.refresh_certificate(hs)
423422

424-
@defer.inlineCallbacks
425-
def start():
423+
async def start():
426424
try:
427425
# Run the ACME provisioning code, if it's enabled.
428426
if hs.config.acme_enabled:
429427
acme = hs.get_acme_handler()
430428
# Start up the webservices which we will respond to ACME
431429
# challenges with, and then provision.
432-
yield defer.ensureDeferred(acme.start_listening())
433-
yield defer.ensureDeferred(do_acme())
430+
await acme.start_listening()
431+
await do_acme()
434432

435433
# Check if it needs to be reprovisioned every day.
436434
hs.get_clock().looping_call(reprovision_acme, 24 * 60 * 60 * 1000)
@@ -439,8 +437,8 @@ def start():
439437
if hs.config.oidc_enabled:
440438
oidc = hs.get_oidc_handler()
441439
# Loading the provider metadata also ensures the provider config is valid.
442-
yield defer.ensureDeferred(oidc.load_metadata())
443-
yield defer.ensureDeferred(oidc.load_jwks())
440+
await oidc.load_metadata()
441+
await oidc.load_jwks()
444442

445443
_base.start(hs, config.listeners)
446444

@@ -456,7 +454,7 @@ def start():
456454
reactor.stop()
457455
sys.exit(1)
458456

459-
reactor.callWhenRunning(start)
457+
reactor.callWhenRunning(lambda: defer.ensureDeferred(start()))
460458

461459
return hs
462460

0 commit comments

Comments
 (0)