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

Check if worker is initialized #705

Merged
merged 11 commits into from
Jan 27, 2024

Conversation

nkaretnikov
Copy link
Contributor

@nkaretnikov nkaretnikov commented Dec 13, 2023

Fixes #605.

Description

conda-store can run via docker and in standalone mode:

  • in standalone mode, the --standalone CLI parameter must be used to start the worker sub-process
  • when running via docker, this CLI parameter is not used because a dedicated worker process is started by docker-compose.

However, there might be cases where users forget to pass the --standalone parameter when running in standalone mode. This is a problem because the server cannot execute any tasks without the worker, so it must be running.

This PR adds a check that verifies whether the worker is running and prints an error message if not.

The worker is configured via a number of parameters, like celery_broker_url, which can either point to a database connection or use Redis:

    @default("celery_broker_url")
    def _default_celery_broker_url(self):
        if self.redis_url is not None:
            return self.redis_url
        return f"sqla+{self.database_url}"

Similarly, checks like conda_store.celery_app.control.inspect().ping() won't work outside of Redis and RabbitMQ.

So we use a database entry to check whether the worker is initialized. The database is used because it will work regardless of parameters used to configure the worker.

Example output:

[CondaStoreServer] WARNING | Waiting for worker... Use --standalone if running outside of docker
[CondaStoreServer] WARNING | Waiting for worker... Use --standalone if running outside of docker
[CondaStoreServer] WARNING | Waiting for worker... Use --standalone if running outside of docker
[CondaStoreServer] Worker initialized

The warning message is printed in red, the info message is printed in green.

The simplest way to test this:

  • run the server in one terminal, wait for warnings to be printed
  • run the worker in another terminal, wait for the info message to be printed.

The commands to run from conda-store/conda-store-server:

terminal1: python -m conda_store_server.server
terminal2: python -m conda_store_server.worker

To test in standalone mode (also starts the worker):

python -m conda_store_server.server --standalone

To test via docker:

docker-compose build --build-arg RELEASE_VERSION=2023.10.1 && docker-compose up

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentation (if required)?
  • Did you add/update relevant tests for this change (if required)?

Additional information

Copy link

netlify bot commented Dec 13, 2023

Deploy Preview for kaleidoscopic-dango-0cf31d canceled.

Name Link
🔨 Latest commit 1863ec0
🔍 Latest deploy log https://app.netlify.com/sites/kaleidoscopic-dango-0cf31d/deploys/65abf0a47d1b2500087bb149

@nkaretnikov
Copy link
Contributor Author

Tested this on Linux and Windows. Example output from Windows (server and worker are running in separate terminals):

Screen Shot 2023-12-18 at 23 25 02

conda-store-server/conda_store_server/server/app.py Outdated Show resolved Hide resolved
conda-store-server/conda_store_server/server/app.py Outdated Show resolved Hide resolved
conda-store-server/conda_store_server/server/app.py Outdated Show resolved Hide resolved
conda-store-server/conda_store_server/orm.py Outdated Show resolved Hide resolved
@nkaretnikov
Copy link
Contributor Author

@dcmcand Please take a look!

Summary of changes:

  • The constants and method are accessible globally, but they are marked as private to avoid polluting the public namespace.
  • The time delay value is now a parameter.
  • Removed the DB constraint, too.
  • Fixed a typo.

Copy link
Contributor

@dcmcand dcmcand left a comment

Choose a reason for hiding this comment

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

🚀 Thanks @nkaretnikov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

[BUG] - without --standalone, server runs but fails to build env
2 participants