conda-incubator / conda-store

Data science environments, for collaboration. ✨
https://conda.store
BSD 3-Clause "New" or "Revised" License
139 stars 45 forks source link

Check if worker is initialized #705

Closed nkaretnikov closed 5 months ago

nkaretnikov commented 7 months ago

Fixes #605.

Description

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

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:

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

Additional information

netlify[bot] commented 7 months ago

Deploy Preview for kaleidoscopic-dango-0cf31d canceled.

Name Link
Latest commit 1863ec04ab7aef201be7de245d170eb12d09efcb
Latest deploy log https://app.netlify.com/sites/kaleidoscopic-dango-0cf31d/deploys/65abf0a47d1b2500087bb149
nkaretnikov commented 7 months ago

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
nkaretnikov commented 6 months ago

@dcmcand Please take a look!

Summary of changes: