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

Build process: use Celery handlers #8815

Merged
merged 98 commits into from
Feb 7, 2022
Merged

Build process: use Celery handlers #8815

merged 98 commits into from
Feb 7, 2022

Commits on Jan 13, 2022

  1. Build process: use Celery handlers

    Initial migration/refactor of the build process to make usage of the Celery
    handlers (`on_success`, `on_failure`, etc)
    humitos committed Jan 13, 2022
    Configuration menu
    Copy the full SHA
    3b758a6 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2022

  1. Configuration menu
    Copy the full SHA
    b7e4683 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    61b5e8b View commit details
    Browse the repository at this point in the history
  3. Test: LocalBuildEnvironment run(), __enter__ and __exit__ required

    We use this environment a lot from our tests, which I don't like. However, for
    now, I'm keeping the because the change is not small.
    
    We should split unit-test from integration test and reduce the complexity of
    executing "real commands" when calling tests in exchange of more mocked data
    instead and unit tests for the logic.
    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    0f8cc23 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f80d2c7 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d3f0dde View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f1c960b View commit details
    Browse the repository at this point in the history
  7. Test: more import moves

    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    c72f02c View commit details
    Browse the repository at this point in the history
  8. Test: avoid short-circuiting the task to test

    Integration tests should not create the environment where to execute the
    commands nor passing weird attributes to the task. They should mock the
    responses of the API for the task to grab the correct data instead.
    
    This way, we avoid having "extra arguments" on the tasks just for test purposes
    and also avoid cheating the normal flow by overriding the environment with
    custom attributes. This creates lot of complexity in our code and we endup with
    multiple different flows that are not normal and won't ever happen in production
    but that we need to maintain just for the tests.
    
    In particular, we should avoid "integration tests" when they are not strictly
    required. In this particular case, we could create a unit-test that checks the
    logic for `SyncRepositoryMixin.validate_duplicate_reserved_versions` which is a
    lot easier to generate the context required and then an "integration test" with
    most things mocked (no `git` commands are executed at all) and only checks that
    function is being called.
    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    bc8c4e8 View commit details
    Browse the repository at this point in the history
  9. Cleanup: remove "Wipe" feature

    We are always using `CLEAN_AFTER_BUILD=True`, so there is no environment to wipe
    anymore. This is a confusing message to send to the user since it has no effect.
    
    I'm also removing the code because it doesn't make sense anymore. If we ever
    need it again, we can re-implement it correctly and recover it from here.
    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    2c07948 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    a5123cc View commit details
    Browse the repository at this point in the history
  11. Cleanup: remove pip cache method helper

    We are not caching pip packages anymore.
    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    640b3d3 View commit details
    Browse the repository at this point in the history
  12. Test: comments and notes about what how to migrate them

    There are lot of tests not really accurate and very complex without reason. I'd
    like to use the same flow in production than in tests instead of
    short-circuiting/hacking the process in tests to behave as we want.
    
    We should use mocks to avoid executing commands when running tests instead, but
    making sure the "build process" is following exact the same flow in both
    environments. If we want to test something in particular outside the flow, we
    should create unit tests for those functions/methods.
    humitos committed Jan 17, 2022
    Configuration menu
    Copy the full SHA
    8df55fd View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2022

  1. Configuration menu
    Copy the full SHA
    a6053d9 View commit details
    Browse the repository at this point in the history
  2. clean_build: pass the version object

    This way we avoid doing an aditional API call to get the version, since we
    already have it in memory.
    humitos committed Jan 18, 2022
    Configuration menu
    Copy the full SHA
    7b382dc View commit details
    Browse the repository at this point in the history
  3. Test: migrate rtd_tests/test_builds.py to new format

    I wasn't able to mock the whole task as I wanted yet, but I follow a similar
    convention than the one used for the migrated test. However, I've simplify them
    a little.
    humitos committed Jan 18, 2022
    Configuration menu
    Copy the full SHA
    4f3e213 View commit details
    Browse the repository at this point in the history

Commits on Jan 19, 2022

  1. Build: re-organize files

    There is no need to have a `base.py` and `BuildTaskBase` because it don't share
    code with sync repository task.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    38a005a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5abb5a7 View commit details
    Browse the repository at this point in the history
  3. Build: follow the same pattern for localmedia than the others

    Skip moving the file if the old artifact path does not exist.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    fdd884d View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    4eaab60 View commit details
    Browse the repository at this point in the history
  5. Test: initial structure to mock the build completely

    Ideally, we should be able to mock:
    
    * API calls
    * Commands run inside the environment
    * Git repository
    * Read the Docs config file
    
    This commit mocks most of them. The only missing here is the config file, but
    there should be code already for that.
    
    These mocks allow us to use the exact same flow than in production (e.g. hitting
    the API to get the Version/Build/Project object) and avoid short-circuiting it.
    Once the "mocked build" is finished, we can assert all the calls to them.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    354da75 View commit details
    Browse the repository at this point in the history
  6. Test: call the task with .delay

    That way, it executes the `on_success`, `on_failure`, etc.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    65d9d04 View commit details
    Browse the repository at this point in the history
  7. Test: check important calls when the build fails

    New test to check that we are updating the build object via the API, we are
    sending notifications and more when the build fails.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    d3e0bb7 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    535834b View commit details
    Browse the repository at this point in the history
  9. Test: full test for successful build

    It checks all the API calls done to the webs, and that the functions we expect
    to be called are effectively called.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    d49ef65 View commit details
    Browse the repository at this point in the history
  10. Test: migrate/update build tests

    Move tests from `test_celery.py` to the "new system" and remove the invalid ones.
    humitos committed Jan 19, 2022
    Configuration menu
    Copy the full SHA
    2fba199 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    2263a53 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    99ad8c1 View commit details
    Browse the repository at this point in the history

Commits on Jan 20, 2022

  1. Configuration menu
    Copy the full SHA
    a359fd6 View commit details
    Browse the repository at this point in the history
  2. Test: more tests migrated

    humitos committed Jan 20, 2022
    Configuration menu
    Copy the full SHA
    b7feb4d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0bf8171 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    03e8bc2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    1273a68 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    5e94afb View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    3311bc3 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    9841b2a View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    cb74e02 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    503d10e View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    e77bd40 View commit details
    Browse the repository at this point in the history

Commits on Jan 21, 2022

  1. Configuration menu
    Copy the full SHA
    d2d6f8a View commit details
    Browse the repository at this point in the history
  2. Build: remove the concept of "forcing a build"

    It was used to "force a build" by omiting the environment cached on disk.
    However, this does not makes sense anymore since we are not caching
    anything (always CLEAN_BUILD=True) and we run just one build per instance.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    2e11886 View commit details
    Browse the repository at this point in the history
  3. Build: remove the ability to (not)record a whole Build object

    We always want to record a Build into our database. However, there are
    _particular_ commands that we don't want to record to not expose them to the
    user.
    
    The un-needed logic was removed to simplify the flow.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    41c4f2f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    a4b1d70 View commit details
    Browse the repository at this point in the history
  5. Build: remove BuildEnvironmentWarning exception

    This was only to communicate `BuildEnvironment.__exit__` that it should not log
    the exception as an error.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    0cc8a73 View commit details
    Browse the repository at this point in the history
  6. Build: make sure we have self.build_pk when handling exceptions

    If the API fails when retriving the build, we should use just the `build_pk`
    passed when triggered the task to report it back. However, the API may fail
    again when hit, but at least it does not fails in our application code.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    41a6d1e View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    a45c703 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    4742600 View commit details
    Browse the repository at this point in the history
  9. Build: differentiate "user errors" from "app errors"

    Show different messages depending on the error type:
    
    - user error: something the user should be able to solve by themselves (e.g.
      wrong RTD config file)
    - app error: nothing the user can do, it's an internal error that we known (e.g.
      can't connect to Docker API)
    - unknown error: we don't know what happened. Log the exception and show a
      generic error to the user
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    f6100be View commit details
    Browse the repository at this point in the history
  10. Cleanup: remove BuildCommand.description

    We are not using that field at all.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    a5c8cc9 View commit details
    Browse the repository at this point in the history
  11. Build: generic message for OOM/timeout when Killed in output

    When the work `Killed` appears in the output it could be OOM or timeout. We
    are not sure. So, we insert a generic message in the build's output saying that
    could be one or the other.
    
    However, if we are _sure_ what the error was, the Exception risen will have the
    proper message and it will be shown correctly to the user.
    humitos committed Jan 21, 2022
    Configuration menu
    Copy the full SHA
    0ca908e View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2022

  1. Build: save 'builder' when its known

    Store the `Build.builder` in `before_start` so it's saved immediately next time
    the Build object is updated instead of at the end of the build process.
    humitos committed Jan 24, 2022
    Configuration menu
    Copy the full SHA
    5d41fed View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6299525 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    00861bc View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6426900 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    ce306aa View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    1c2eb6a View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    92e701b View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    40c373c View commit details
    Browse the repository at this point in the history
  9. VCS support: normalize error reporting

    `BaseVCS` class is raising a `RepositoryError` exception when the command
    executed in the environment fails. The logic is as follows:
    
    - Environment runs the command
    - Raises a BuildUserError if the command fails
    - `BaseVCS` detects this exception and re-raise a `RepositoryError`
    
    Each VCS Backend class, handle this `RepositoryError` nicely and return whatever
    is required in that case.
    humitos committed Jan 24, 2022
    Configuration menu
    Copy the full SHA
    2f6d89b View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    a530ad9 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    9e017c9 View commit details
    Browse the repository at this point in the history
  12. Merge branch 'master' of github.com:readthedocs/readthedocs.org into …

    …humitos/celery-handlers
    humitos committed Jan 24, 2022
    Configuration menu
    Copy the full SHA
    ceb3dcc View commit details
    Browse the repository at this point in the history
  13. Docs: add todo comment

    humitos committed Jan 24, 2022
    Configuration menu
    Copy the full SHA
    4f06286 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    aba7b1e View commit details
    Browse the repository at this point in the history
  15. Deploy: re-define the task under readthedocs.projects.tasks

    We need to re-define this task here to avoid old web instances trigger these
    tasks while new builders won't have it configured.
    
    Probably, we will want to deploy builders first.
    humitos committed Jan 24, 2022
    Configuration menu
    Copy the full SHA
    d5a8ffb View commit details
    Browse the repository at this point in the history

Commits on Jan 26, 2022

  1. Build: remove version locking

    Since we are using only 1 process per builder, there is no need to have a
    mechanisim to check if there is another build running in the host and lock the
    version.
    
    This commit removes all the locking mechanisim to simplify the code and reduce
    complexity. We can come back to this if we need it again in the future.
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    48c3507 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    91a2e9a View commit details
    Browse the repository at this point in the history
  3. Cleanup: remove setting Build fields that are not used

    These fields were used long time ago and are not required anymore. We can go a
    little further in the future and remove the database fields as well.
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    d0a22e2 View commit details
    Browse the repository at this point in the history
  4. Build: improve copy for user facing error messages

    Co-authored-by: Anthony <aj@ohess.org>
    humitos and agjohnson authored Jan 26, 2022
    Configuration menu
    Copy the full SHA
    d27e487 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    a393ddb View commit details
    Browse the repository at this point in the history
  6. Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…

    …thedocs.org into humitos/celery-handlers
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    0f8af38 View commit details
    Browse the repository at this point in the history
  7. Celery: add more renamed tasks

    I thought they weren't required because, but they are. It could happen that
    `fileify` tasks get queued and while we are deploying webs. In that case, when
    new web instances spun up they won't have the old name defined.
    
    So, it's a good idea to define the old name for these tasks as well.
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    b3d7491 View commit details
    Browse the repository at this point in the history
  8. Celery: make required arguments mandatory for build tasks

    - sync_repository_task: must receive `version_id`
    - update_docs_task: must receive `version_id` and `build_id` and optionally a `build_commit`
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    9fff24f View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    ac24233 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    928cabf View commit details
    Browse the repository at this point in the history
  11. Test: cleanup old tests

    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    f48abbd View commit details
    Browse the repository at this point in the history
  12. Build: rename tasks in router

    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    fb27227 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    d35d5c8 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    a3bc857 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    41216c8 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    99c704d View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    7534a84 View commit details
    Browse the repository at this point in the history
  18. CircleCI: give more memory to elasticsearch

    Hopefully with this it doesn't exit with `Exited with code 137`
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    40a7750 View commit details
    Browse the repository at this point in the history
  19. Merge branch 'master' of github.com:readthedocs/readthedocs.org into …

    …humitos/celery-handlers
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    21c3f10 View commit details
    Browse the repository at this point in the history
  20. Docs: delete wipe docs

    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    68f257f View commit details
    Browse the repository at this point in the history
  21. Celery: re-register tasks with the old name

    This allows new builds to execute tasks triggered by old web instances while
    doing the deploy.
    
    This code can be removed after that.
    humitos committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    9154e8d View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    1e9c724 View commit details
    Browse the repository at this point in the history

Commits on Feb 1, 2022

  1. Lint: undefined variable

    humitos committed Feb 1, 2022
    Configuration menu
    Copy the full SHA
    8b237a3 View commit details
    Browse the repository at this point in the history
  2. Celery: use an internal namespace to store build task's data

    Use a `Task.data` (`readthedocs.projects.task.builds.TaskData` object) to store
    all the data the task needs to work instead of storing it directly using
    `self.`.
    
    This is to allow us a simpler way to perform a clean _before_ (and/or _after_)
    starting the execution of a new task and avoid potentially sharing state with a
    previous task executed that may not be able to perform the cleanup.
    
    The only thing we need to keep in mind is that when modifying these Celery
    tasks, we _always_ have to add any new value inside the
    `self.data.<my-new-attribute>` and not directly `self.<my-new-attribute>` to
    avoid this problem. In the future, we could implement this protection at a code
    level if we want to avoid this mistake.
    
    See #8815 (comment)
    See https://docs.celeryproject.org/en/master/userguide/tasks.html#instantiation
    humitos committed Feb 1, 2022
    Configuration menu
    Copy the full SHA
    174985a View commit details
    Browse the repository at this point in the history

Commits on Feb 3, 2022

  1. Configuration menu
    Copy the full SHA
    699fe96 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…

    …thedocs.org into humitos/celery-handlers-self
    humitos committed Feb 3, 2022
    Configuration menu
    Copy the full SHA
    e08c00e View commit details
    Browse the repository at this point in the history
  3. Lint

    humitos committed Feb 3, 2022
    Configuration menu
    Copy the full SHA
    017df68 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    a546f59 View commit details
    Browse the repository at this point in the history
  5. Lint

    humitos committed Feb 3, 2022
    Configuration menu
    Copy the full SHA
    4c89df1 View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2022

  1. Configuration menu
    Copy the full SHA
    fde6a1a View commit details
    Browse the repository at this point in the history
  2. Re-structure: move search utils tasks into ...tasks.search

    I wasn't able to find nor solve the problem with the `cyclic-import` error
    reported by pylint. So, I tried moving the utils functions used by search tasks
    out from `readthedocs.projects.tasks.utils` into
    `readthedocs.projects.tasks.search` instead.
    
    This made `prospector` and `pylint` to pass locally without reporting any issue.
    humitos committed Feb 7, 2022
    Configuration menu
    Copy the full SHA
    f8ab09e View commit details
    Browse the repository at this point in the history
  3. Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…

    …thedocs.org into humitos/celery-handlers-self
    humitos committed Feb 7, 2022
    Configuration menu
    Copy the full SHA
    2491854 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b68730d View commit details
    Browse the repository at this point in the history