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

Support for object-oriented WorkerSettings classes #472

Open
chrisguidry opened this issue Jul 22, 2024 · 0 comments
Open

Support for object-oriented WorkerSettings classes #472

chrisguidry opened this issue Jul 22, 2024 · 0 comments

Comments

@chrisguidry
Copy link
Contributor

In the current implementation, we're only looking at the __dict__ of the user's provided WorkerSettings class, which can be quite misleading if you're trying to get a large multi-queue system set up. The on_startup/on_shutdown hooks are similarly only allowed to be plain functions or @staticmethod, but not @classmethod because those aren't directly callable.

Example of things that could work naturally:

class BaseWorkerSettings:
    redis_settings = get_my_common_redis_settings()

    @classmethod
    async def on_startup(cls, context: dict[str, Any]):
        ...do some common initialization on all workers...

class FastLane(BaseWorkerSettings):
    queue_name = "arq:fast-lane"
    tasks = [task_a, task_b]


class SlowLane(BaseWorkerSettings):
    queue_name = "arq:slow-lane"
    tasks = [task_c, task_d]

    @classmethod
    async def on_startup(cls, context: dict[str, Any]):
        await super().on_startup(context))
        ...do some specialized initialization on just this worker...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant