Compare commits

..

2 Commits

Author SHA1 Message Date
f6034a32fc 修正任务完成信息的打印逻辑,移除重复输出
All checks were successful
Sync Container Images / sync-images (push) Successful in 2m20s
2025-04-17 21:28:00 +08:00
be652dfadd 优化任务处理逻辑,修正任务函数以确保正确执行 docker_pull、docker_tag 和 docker_push 操作 2025-04-17 21:27:42 +08:00

40
sync.py
View File

@@ -62,26 +62,46 @@ async def main():
for image in config.images:
if len(image.tags) > 0:
for tag in image.tags:
async def task() -> int | None:
return (await docker_pull(f"{image.source}:{tag}")) \
or (await docker_pull(f"{image.source}:{tag}")) \
or (await docker_push(f"{image.target}:{tag}"))
# 定义任务函数
async def task():
if r := await docker_pull(f"{image.source}:{tag}"):
if r != 0:
return r
await docker_tag(f"{image.source}:{tag}", f"{image.target}:{tag}")
if r := await docker_push(f"{image.target}:{tag}"):
if r != 0:
return r
await docker_push(f"{image.target}:{tag}")
if r := await docker_push(image.target):
if r != 0:
return r
return 0
# 将协程对象添加到任务列表
tasks.append(limited_task(task))
else:
async def task() -> int | None:
return (await docker_pull(image.source)) \
or (await docker_pull(image.source)) \
or (await docker_push(image.target))
async def task():
if r := await docker_pull(image.source):
if r != 0:
return r
if r:= await docker_tag(image.source, image.target):
if r != 0:
return r
if r := await docker_push(image.target):
if r != 0:
return r
return 0
tasks.append(limited_task(task))
results = await asyncio.gather(*tasks)
print(tasks)
failed_tasks = 0
for result in results:
if result is not None and result != 0:
failed_tasks += 1
print(f"{len(results)} tasks completed. {len(results) - failed_tasks} succeed, {failed_tasks} failed.")
if failed_tasks > 0:
raise Exception(f"{failed_tasks} tasks failed.")
if __name__ == "__main__":
asyncio.run(main())