add
This commit is contained in:
@@ -30,8 +30,11 @@ class GitHubActionsManager:
|
||||
self.log(f"Failed to delete run with ID {run_id}. Status code: {response.status_code}") # 打印错误信息
|
||||
|
||||
def delete_old_runs(self):
|
||||
while True: # 无限循环,直到没有符合条件的运行记录为止
|
||||
next_page = self.runs_url # 初始化下一页的URL为第一页
|
||||
page_number = 1 # 初始化页数计数器
|
||||
any_deleted = False # 标记是否有记录被删除
|
||||
|
||||
while next_page: # 循环直到没有下一页
|
||||
self.log(f"Fetching page {page_number}") # 输出当前的页数
|
||||
# 发送GET请求获取一页工作流运行记录
|
||||
@@ -49,10 +52,14 @@ class GitHubActionsManager:
|
||||
time_difference = self.current_time - run_time
|
||||
if time_difference > timedelta(hours=hour_count): # 如果差值超过指定小时 默认168小时
|
||||
self.delete_run(run["id"]) # 删除运行记录
|
||||
any_deleted = True # 标记有记录被删除
|
||||
else: # 如果请求失败
|
||||
self.log(f"Failed to fetch runs. Status code: {response.status_code}") # 打印错误信息
|
||||
break # 退出循环
|
||||
|
||||
if not any_deleted: # 如果没有任何记录被删除,退出循环
|
||||
break
|
||||
|
||||
def log(self, message):
|
||||
current_time_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f")[:-3] # 获取当前时间,精确到三位毫秒
|
||||
print(f"{current_time_str} {message}") # 打印日志消息
|
||||
|
||||
Reference in New Issue
Block a user