-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix celery configuration not being applied sometimes #223
Conversation
The module dispatching the celery tasks did not import our celery worker module, which resulted in the celery configuration not being applied in some cases, e.g. when using uvicorn's hot reload functionality. By referencing the celery tasks directly, we make sure that the celery config used for defining the tasks is also used for dispatching them. See https://docs.celeryq.dev/en/stable/userguide/application.html#breaking-the-chain for more information.
7fc48f1
to
403863c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhh nice! I didn't think about that this is now possible. The historical reason why we had to use Signature and a string that points to the function was, that we could not import the methods in the backend_api
worker process because it would load the ML models thus requiring many dependencies. Now we moved all ML stuff to the ray
worker, which make your changes possible.
The only question I have here is, why you import the tasks in the *_async()
functions? Shouldn't it be possible to import them at root level? Because if you import them in the functions, the celery related code gets imported at runtime in the backend_api
worker. But then again I'm wondering if this is working?
I put the import statements into the functions because they would otherwise have caused an import cyle:
I've tested uploading and processing documents with this change and it worked fine.
I'm not sure which celery-related code you mean. Is the backend_api worker the container running the celery worker? How would you expect this to break? |
I meant the |
To keep the decoupling, we could also just I've tested this and it works fine, so if you're happy with it I'd say we can merge it :) |
Alright! Then, let's meeeerge ;) |
The module dispatching the celery tasks did not import our celery worker module, which resulted in the celery configuration not being applied in some cases, e.g. when using uvicorn's hot reload functionality.
By referencing the celery tasks directly, we make sure that the celery config used for defining the tasks is also used for dispatching them.
See https://docs.celeryq.dev/en/stable/userguide/application.html#breaking-the-chain for more information.
fixes #219