maintainers/scripts/update: Prepare for ordered updates

Just minor refactorings:

- Extract `updater_tasks` into a variable.
- Make `main` itself async.

Changed files
+27 -23
maintainers
scripts
+27 -23
maintainers/scripts/update.py
···
# Prepare updater workers for each temp_dir directory.
# At most `num_workers` instances of `run_update_script` will be running at one time.
-
updaters = asyncio.gather(
-
*[
-
updater(
-
nixpkgs_root,
-
temp_dir,
-
merge_lock,
-
packages_to_update,
-
keep_going,
-
commit,
-
)
-
for temp_dir in temp_dirs
-
]
)
try:
# Start updater workers.
-
await updaters
except asyncio.exceptions.CancelledError:
# When one worker is cancelled, cancel the others too.
-
updaters.cancel()
except UpdateFailedException as e:
# When one worker fails, cancel the others, as this exception is only thrown when keep_going is false.
-
updaters.cancel()
eprint(e)
sys.exit(1)
-
def main(
max_workers: int,
keep_going: bool,
commit: bool,
···
eprint()
eprint("Running update for:")
-
asyncio.run(start_updates(max_workers, keep_going, commit, packages))
eprint()
eprint("Packages updated!")
···
args = parser.parse_args()
try:
-
main(
-
args.max_workers,
-
args.keep_going,
-
args.commit,
-
args.packages,
-
args.skip_prompt,
)
except KeyboardInterrupt as e:
# Let’s cancel outside of the main loop too.
···
# Prepare updater workers for each temp_dir directory.
# At most `num_workers` instances of `run_update_script` will be running at one time.
+
updater_tasks = [
+
updater(
+
nixpkgs_root,
+
temp_dir,
+
merge_lock,
+
packages_to_update,
+
keep_going,
+
commit,
+
)
+
for temp_dir in temp_dirs
+
]
+
+
tasks = asyncio.gather(
+
*updater_tasks,
)
try:
# Start updater workers.
+
await tasks
except asyncio.exceptions.CancelledError:
# When one worker is cancelled, cancel the others too.
+
tasks.cancel()
except UpdateFailedException as e:
# When one worker fails, cancel the others, as this exception is only thrown when keep_going is false.
+
tasks.cancel()
eprint(e)
sys.exit(1)
+
async def main(
max_workers: int,
keep_going: bool,
commit: bool,
···
eprint()
eprint("Running update for:")
+
await start_updates(max_workers, keep_going, commit, packages)
eprint()
eprint("Packages updated!")
···
args = parser.parse_args()
try:
+
asyncio.run(
+
main(
+
args.max_workers,
+
args.keep_going,
+
args.commit,
+
args.packages,
+
args.skip_prompt,
+
)
)
except KeyboardInterrupt as e:
# Let’s cancel outside of the main loop too.