Skip to content

Commit 1d4b5e4

Browse files
committed
feat: return task result, not task
1 parent 20842a3 commit 1d4b5e4

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

webapp/github.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ def get_repository_tree(self, repository: str, branch: str = "main"):
118118
raise
119119
for item in data["tree"]:
120120
if item["type"] == "blob" and item["path"].startswith("templates"):
121-
task = async_save_file(
121+
async_save_file(
122122
tree_file_path=str(tree_file_path),
123123
repository=repository,
124124
path=item["path"],
125125
)
126-
task()
127126

128127

129128
@register_task()
@@ -140,19 +139,14 @@ def async_save_file(
140139
path (str): The remote path to the file inside the repository.
141140
tree_file_path (str): The local path where the file will be saved.
142141
"""
143-
try:
144-
github = GitHub()
145-
github.logger.info(f"File path {path}")
146-
content = github.get_file_content(repository, path)
147-
github.logger.info(f"File {path} downloaded")
148-
149-
file_path = Path(tree_file_path) / path
150-
file_path.parent.mkdir(parents=True, exist_ok=True)
151-
152-
with file_path.open("wb") as file:
153-
file.write(content)
154-
except Exception as e:
155-
github.logger.exception(f"Failed to save file: {e}")
142+
github = GitHub()
143+
content = github.get_file_content(repository, path)
144+
145+
file_path = Path(tree_file_path) / path
146+
file_path.parent.mkdir(parents=True, exist_ok=True)
147+
148+
with file_path.open("wb") as file:
149+
file.write(content)
156150

157151

158152
def init_github(app: flask.Flask) -> None:

webapp/tasks.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import os
33
from collections.abc import Callable
4+
from typing import Any
45

56
from celery import current_app as celery_app
67

@@ -20,7 +21,7 @@ def outerwrapper(func: Callable) -> Callable:
2021
register_celery_task(func, celery_app=celery_app)
2122

2223
@functools.wraps(func)
23-
def wrapper(*args: tuple, **kwargs: dict) -> Callable:
24+
def wrapper(*args: tuple, **kwargs: dict) -> Any:
2425
if os.getenv("REDIS_HOST"):
2526
# Run the Celery task
2627
task = run_celery_task(
@@ -39,11 +40,8 @@ def wrapper(*args: tuple, **kwargs: dict) -> Callable:
3940
kwargs=kwargs,
4041
)
4142

42-
# Start scheduled tasks
43-
if delay:
44-
task.delay(*args, **kwargs)
45-
46-
return task.delay
43+
# Start task
44+
return task.delay(*args, **kwargs)
4745

4846
return wrapper
4947

0 commit comments

Comments
 (0)