Skip to content

Commit 19be25a

Browse files
committed
Fix CI
1 parent d1b21d9 commit 19be25a

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed

src/main.py

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ async def remove_old_repositories():
3636
3737
The repository URL is extracted from the first .txt file in each directory,
3838
assuming the filename format: "owner-repository.txt"
39+
40+
Returns
41+
-------
42+
None
43+
This coroutine never returns, it runs indefinitely until cancelled.
3944
"""
4045
while True:
4146
try:
@@ -52,36 +57,67 @@ async def remove_old_repositories():
5257
if current_time - os.path.getctime(folder_path) <= DELETE_REPO_AFTER:
5358
continue
5459

55-
# Try to log repository URL before deletion
56-
try:
57-
txt_files = [f for f in os.listdir(folder_path) if f.endswith(".txt")]
58-
if txt_files:
59-
filename = txt_files[0].replace(".txt", "")
60-
if "-" in filename:
61-
owner, repo = filename.split("-", 1)
62-
repo_url = f"https://github.com/{owner}/{repo}"
63-
with open("history.txt", "a") as history:
64-
history.write(f"{repo_url}\n")
65-
except Exception as e:
66-
print(f"Error logging repository URL for {folder_path}: {str(e)}")
67-
68-
# Delete the folder
69-
try:
70-
shutil.rmtree(folder_path)
71-
except Exception as e:
72-
print(f"Error deleting {folder_path}: {str(e)}")
60+
await process_folder(folder_path)
7361

7462
except Exception as e:
7563
print(f"Error in remove_old_repositories: {str(e)}")
7664

7765
await asyncio.sleep(60)
7866

67+
return
68+
69+
70+
async def process_folder(folder_path: str) -> None:
71+
"""
72+
Process a single folder for deletion and logging.
73+
74+
Parameters
75+
----------
76+
folder_path : str
77+
The path to the folder to be processed.
78+
79+
Returns
80+
-------
81+
None
82+
This function doesn't return anything but performs side effects.
83+
"""
84+
# Try to log repository URL before deletion
85+
try:
86+
txt_files = [f for f in os.listdir(folder_path) if f.endswith(".txt")]
87+
if txt_files:
88+
filename = txt_files[0].replace(".txt", "")
89+
if "-" in filename:
90+
owner, repo = filename.split("-", 1)
91+
repo_url = f"https://github.com/{owner}/{repo}"
92+
with open("history.txt", "a", encoding="utf-8") as history:
93+
history.write(f"{repo_url}\n")
94+
except Exception as e:
95+
print(f"Error logging repository URL for {folder_path}: {str(e)}")
96+
97+
# Delete the folder
98+
try:
99+
shutil.rmtree(folder_path)
100+
except Exception as e:
101+
print(f"Error deleting {folder_path}: {str(e)}")
102+
103+
return
104+
79105

80106
@asynccontextmanager
81-
async def lifespan(app: FastAPI):
107+
async def lifespan(_: FastAPI):
82108
"""
83109
Lifecycle manager for the FastAPI application.
84110
Handles startup and shutdown events.
111+
112+
Parameters
113+
----------
114+
_ : FastAPI
115+
The FastAPI application instance (unused).
116+
117+
Yields
118+
-------
119+
None
120+
Yields control back to the FastAPI application while the background task runs.
85121
"""
86122
task = asyncio.create_task(remove_old_repositories())
87123

0 commit comments

Comments
 (0)