conda-incubator / conda-store

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

Define all task ids in one place #691

Open nkaretnikov opened 8 months ago

nkaretnikov commented 8 months ago

Context

See https://github.com/conda-incubator/conda-store/pull/531#discussion_r1298250683

Probably put this in conda-store-server/conda_store_server/worker/tasks.py.

Something like (we use a similar pattern in other places, e.g., BuildKey):

# Singleton class that hides impl details, supposed to be used only via class methods
class TaskId:
    _ids = {
        "build-conda-env-export": "build-{build_id}-conda-env-export",
...
    # more task ids here
    }

    # add another method allowing to get all ids, e.g., to be able to cancel all build-specific tasks
    # we have non-build task ids as well - add a way to get a group of tasks? maybe something like build_ids and other

    @classmethod
    def get_task_id_build_conda_env_export(cls, build_id):
        # use the _ids above

...

Then this needs to be used in create_build and api_put_build_cancel.

Value and/or benefit

Ids to cancel will be automatically updated, which is less error-prone

Anything else?

No response