fix: Refactor file reading and async task creation, fix return type in vertex_builds model (#4273)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-10-30 21:27:05 -03:00 committed by GitHub
commit fab2d9afb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 12 deletions

View file

@ -329,7 +329,7 @@ async def build_flow(
client_consumed_queue: asyncio.Queue,
event_manager: EventManager,
) -> None:
build_task = asyncio.create_task(asyncio.to_thread(asyncio.run, _build_vertex(vertex_id, graph, event_manager)))
build_task = asyncio.create_task(_build_vertex(vertex_id, graph, event_manager))
try:
await build_task
except asyncio.CancelledError as exc:
@ -361,8 +361,8 @@ async def build_flow(
async def event_generator(event_manager: EventManager, client_consumed_queue: asyncio.Queue) -> None:
if not data:
# using another thread since the DB query is I/O bound
vertices_task = asyncio.create_task(asyncio.to_thread(asyncio.run, build_graph_and_get_order()))
# using another task since the build_graph_and_get_order is now an async function
vertices_task = asyncio.create_task(build_graph_and_get_order())
try:
await vertices_task
except asyncio.CancelledError:

View file

@ -93,15 +93,16 @@ class DirectoryReader:
_file_path = Path(file_path)
if not _file_path.is_file():
return None
with _file_path.open(encoding="utf-8") as file:
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3069: character maps to <undefined>
try:
try:
with _file_path.open(encoding="utf-8") as file:
# UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 3069:
# character maps to <undefined>
return file.read()
except UnicodeDecodeError:
# This is happening in Windows, so we need to open the file in binary mode
# The file is always just a python file, so we can safely read it as utf-8
with _file_path.open("rb") as f:
return f.read().decode("utf-8")
except UnicodeDecodeError:
# This is happening in Windows, so we need to open the file in binary mode
# The file is always just a python file, so we can safely read it as utf-8
with _file_path.open("rb") as f:
return f.read().decode("utf-8")
def get_files(self):
"""Walk through the directory path and return a list of all .py files."""

View file

@ -50,7 +50,7 @@ class VertexBuildBase(SQLModel):
return truncate_long_strings(data)
@field_serializer("params")
def serialize_params(self, data) -> dict:
def serialize_params(self, data) -> str:
return truncate_long_strings(data)