多线程优化

This commit is contained in:
2024-09-17 09:25:20 +08:00
parent 652bd27924
commit 6e9a49e054
2 changed files with 29 additions and 14 deletions
+3 -1
View File
@@ -3,7 +3,9 @@ on:
workflow_call: workflow_call:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: "0 * * * *" - cron: "0 0 * * *"
- cron: "0 10 * * *"
- cron: "0 20 * * *"
jobs: jobs:
sync: sync:
+26 -13
View File
@@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
import os import os
import sys import sys
import time
import requests import requests
import threading
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
dataHeaders = { dataHeaders = {
@@ -30,19 +32,8 @@ for i in range(1, len(sys.argv)):
if (i % 2 == 0): if (i % 2 == 0):
password.append(sys.argv[i]) password.append(sys.argv[i])
def sync(i):
global thread
data = requests.get("https://github.com/orgs/GXDE-OS/repos_list?q=&page=1", headers=dataHeaders).json()
# 获取页数
page = int(data["pageCount"])
repoList = []
# 获取仓库列表
for i in range(1, page + 1):
pageData = requests.get(f"https://github.com/orgs/GXDE-OS/repos_list?q=&page={i}", headers=dataHeaders).json()
repositories = pageData["repositories"]
for j in repositories:
repoList.append(j["name"])
for i in repoList:
# 拉取代码进行同步 # 拉取代码进行同步
if (not os.path.exists(f"{programPath}/git-clone")): if (not os.path.exists(f"{programPath}/git-clone")):
os.makedirs(f"{programPath}/git-clone") os.makedirs(f"{programPath}/git-clone")
@@ -56,4 +47,26 @@ for i in repoList:
os.system(f"cd '{programPath}/git-clone/{i}.git' ; git push --mirror") os.system(f"cd '{programPath}/git-clone/{i}.git' ; git push --mirror")
# 移除临时文件 # 移除临时文件
os.system(f"rm -rf '{programPath}/git-clone/{i}.git'") os.system(f"rm -rf '{programPath}/git-clone/{i}.git'")
thread -= 1
data = requests.get("https://github.com/orgs/GXDE-OS/repos_list?q=&page=1", headers=dataHeaders).json()
# 获取页数
page = int(data["pageCount"])
repoList = []
# 获取仓库列表
for i in range(1, page + 1):
pageData = requests.get(f"https://github.com/orgs/GXDE-OS/repos_list?q=&page={i}", headers=dataHeaders).json()
repositories = pageData["repositories"]
for j in repositories:
repoList.append(j["name"])
# 多线程处理以提升速度
thread = 0
threadMax = 10
for i in repoList:
while True:
time.sleep(0.1)
if (thread < threadMax):
threading.Thread(target=sync, args=[i]).start()
thread += 1
break