Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(backend,taxonomy-editor-frontend): Handle background task on frontend #316

Closed
wants to merge 9 commits into from

Conversation

Piv94165
Copy link
Contributor

@Piv94165 Piv94165 commented Dec 20, 2023

Current situation

  • If parsing takes too long, the frontend times out, resulting in a timeout notification :

Image

  • Only successfully parsed taxonomies are displayed in the existing projects list. Failed or loading taxonomies are not visible.

To be done

  • Project Creation Page: Users should land on a loading page upon creating a project, prompting them to refresh the page for updates
  • Projects Listing: Ensure all projects are visible in the table, including those that failed or are still loading
  • ¨Project Status: Display project statuses (successfully parsed, parsing failed, parsing in progress) in the projects list

These enhancements will offer a more comprehensive view of project statuses, provide clarity to users during parsing, and ensure visibility of all projects in the list, even if parsing fails or takes longer than expected.

Screenshot

image
A small text reminds user to reload the page to see taxonomy

image
In the list, the project status is displayed.
Not only the open projects are listed but also the other ones.

Part of

(https://github.com/orgs/openfoodfacts/projects/103/views/1?pane=issue&itemId=46878339)

@Piv94165 Piv94165 linked an issue Dec 20, 2023 that may be closed by this pull request
3 tasks
@Piv94165
Copy link
Contributor Author

Piv94165 commented Dec 20, 2023

Link: #304 (comment) needs to be merged prior to this PR for correct functionality.

Remarks:
During the import of a taxonomy, the task runs in the background. However, the backend is unable to send any response due to the synchronous nature of the following functions:

self.create_nodes(filename, multi_label)
self.create_child_link(multi_label)
self.create_previous_link(multi_label)
self.create_fulltext_index(taxonomy_name, branch_name)
self.create_parsing_errors_node(taxonomy_name, branch_name)

This results in the page loading indefinitely if the user tries to access existing projects while a new project is being created, as the backend cannot respond to the frontend until parsing is complete.

The synchronicity of these functions appears to be causing the backend's inability to respond to the frontend. Converting them to asynchronous operations might be necessary to resolve this issue.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Small improvement proposed.

Comment on lines 127 to 128
async with TransactionCtx():
await self.set_project_status(status="FAILED")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could set project status FAILED only if create_project did not fail ? (create project could return created project and you could test it here, remember to create the variable with None before the try though to be sure it exists.

@Piv94165 Piv94165 force-pushed the refactor/handle-background-task-on-frontend branch from 1f9c964 to 88350fb Compare January 10, 2024 17:35
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank @Piv94165 !

There are still a bit of things to improve.

backend/editor/entries.py Show resolved Hide resolved
backend/editor/entries.py Show resolved Hide resolved
backend/editor/entries.py Show resolved Hide resolved
backend/editor/entries.py Show resolved Hide resolved
backend/editor/entries.py Show resolved Hide resolved
@@ -29,22 +29,30 @@ const GoToProject = ({ clearNavBarLinks }: Props) => {
const navigate = useNavigate();

const { data, isPending, isError } = useFetch<ProjectsAPIResponse>(
`${API_URL}projects?status=OPEN`
`${API_URL}projects`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, in another PR I think we will have to provide a way to filter by status !

backend/editor/entries.py Show resolved Hide resolved
@alexgarel
Copy link
Member

@Piv94165 should we close this PR ? If I remember well you merged those changes in another PR right ?

@Piv94165 Piv94165 closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Handle background tasks on Frontend
2 participants