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

Migrate sync_versions from an API call to a task #7548

Merged
merged 13 commits into from
Jan 5, 2021
Merged

Conversation

ericholscher
Copy link
Member

This should stop the API from timing out,
since we aren’t running all this logic in process.
This is most important for projects with lots of versions,
because this logic takes a long time to run and times out the web processes.
It also eats up our API processes,
causing other issues with our API because of blocking.

To test this, you can use the pull management command on a project you have checked out locally:

inv -e docker.manage 'pull time-test’

This should stop the API from timing out,
since we aren’t running all this logic in process.
This is most important for projects with lots of versions,
because this logic takes a long time to run and times out the web processes.
It also eats up our API processes,
causing other issues with our API because of blocking.

To test this, you can use the `pull` management command on a project you have checked out locally:

```
inv -e docker.manage 'pull time-test’
```
@ericholscher ericholscher requested a review from a team October 7, 2020 23:12
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me! I left one comment in particular about a potential edge case and two if block added that I think are not needed.

readthedocs/core/management/commands/pull.py Show resolved Hide resolved
readthedocs/projects/tasks.py Show resolved Hide resolved
readthedocs/projects/tasks.py Show resolved Hide resolved
readthedocs/builds/tasks.py Outdated Show resolved Hide resolved
readthedocs/projects/tasks.py Outdated Show resolved Hide resolved
@ericholscher ericholscher added the PR: work in progress Pull request is not ready for full review label Oct 8, 2020
@ericholscher
Copy link
Member Author

I need to fix up this test, but would love a quick review on the basic idea here.

@ericholscher
Copy link
Member Author

I think this is a solid PR, but needs a bunch of test refactoring. I'll jump on it soonish hopefully.

@stale
Copy link

stale bot commented Dec 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Dec 5, 2020
@ericholscher ericholscher added the Accepted Accepted issue on our roadmap label Dec 7, 2020
@stale stale bot removed the Status: stale Issue will be considered inactive soon label Dec 7, 2020
@stsewd
Copy link
Member

stsewd commented Dec 10, 2020

I have updated this PR

  • Split argument into tags and branches data
  • Update with the latest changes from sync_versions
  • Make it backwards compatible (the api endpoint still works)

Still need to update the tests and test it locally.

- Split into tags and branches data
- Update with latest changes from sync_versions
- Make it backwards compatible
log.exception('Sync Versions Exception')
except Exception:
log.exception('Unknown Sync Versions Exception')
from readthedocs.builds import tasks as build_tasks
Copy link
Member

Choose a reason for hiding this comment

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

circular imports everywhere!

Copy link
Member

Choose a reason for hiding this comment

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

We could avoid it by moving send_build_status to this file as well.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +232 to +233
:param tags_data: List of dictionaries with ``verbose_name`` and ``identifier``.
:param branches_data: Same as ``tags_data`` but for branches.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should refactor these to be a list of named tuples, I think celery should do fine serializing them, but for another PR anyway...

Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably be in a TODO in the code, then :)

@stsewd
Copy link
Member

stsewd commented Dec 14, 2020

Looks like this is working fine locally, we could also put it under a feature flag if we want, since the api is still working.

@stsewd stsewd removed the PR: work in progress Pull request is not ready for full review label Dec 14, 2020
@stsewd stsewd requested a review from a team December 14, 2020 19:40
@stsewd
Copy link
Member

stsewd commented Dec 14, 2020

Looks like Eric can't review this PR since he opened it :D

stsewd added a commit that referenced this pull request Dec 16, 2020
Mostly to avoid a circular import in #7548 (comment)

Also, make projects/tasks.py more project related and small :D
Copy link
Member Author

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks like a solid change 👍

I think a feature flag would be a good idea, so we can deploy it without much risk. Having it be backwards compat is a really good idea :)

Comment on lines +232 to +233
:param tags_data: List of dictionaries with ``verbose_name`` and ``identifier``.
:param branches_data: Same as ``tags_data`` but for branches.
Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably be in a TODO in the code, then :)

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me!

readthedocs/api/v2/views/model_views.py Show resolved Hide resolved
identifier = getattr(self, 'commit', None) or self.version.identifier
version_repo.checkout(identifier)

def sync_versions_api(self, version_repo):
def sync_versions_task(self, version_repo):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can call this trigger_sync_versions or trigger_sync_versions_task, to avoid having the same name for this method than for the real task.

readthedocs/builds/tasks.py Outdated Show resolved Hide resolved
@stsewd stsewd merged commit 0c59910 into master Jan 5, 2021
@stsewd stsewd deleted the sync-repo-celery branch January 5, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants