-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Celery does not pickup class based tasks #3744
Comments
I believe you have to use |
@ddemid hello! Thanks for the help. but no good :( I've tried two things:
Like so:
Still, none of these tasks have been picked up. The tasks that have been pickedup are function based.
|
Just to clarify: I need these to be class based tasks, because there is currently some discovery behavior that I need to support. The user can choose these tasks and they have some "special" attributes that I need to support. The validation_class, name and description, are used by Django Rest Framework. |
@rickwargo where are you registering those? How did you configured the CELERY_IMPORTS or the autodiscover? I've tried to do the registering myself, but no dice. |
Not using autodiscover. I'm registering after I define the class. Here's an example of a class-based task I use where I am using I am using a custom router (maps between lib.task and myapp) and my
|
Oh, now we're talking :D. I've managed to this. We already had a loader that check all of those tasks (BaseTask) children. So I just added the new register to that method. There is a lot of boilerplate to add these tasks to models in DB, but something like this should work for a global registry. Check this:
Here is the celery start output:
👏 👏 👏 @ask perhaps we should add this to the docs? Before migrating to 4.0.2 (I don't remember which version I was using) these tasks were automatically found. |
Please add it to the docs; I lost a lot of time today while upgrading to celery 4.0.2. We use class based tasks a lot in our project as we have some basic functionality in them (sort of a Mixin) and all tasks inherit from it; before 4.0.2 it autodiscovered these class based tasks just fine. Maybe off topic: I'll have some time next week, to write a short tutorial or to write a chapter in the docs about it. |
After messing around with this quite a bunch, it's clear to me that you're not intended to use class-based tasks anymore. Always use the decorator approach instead. I even wrote up a custom loader so that I could keep it the old way, following the instructions in the docs ( Moral of the story: Celery 4 is time to bite the bullet and stop using class-based tasks. It turns out they are confusing to use anyway, since the task instance lives longer than you're likely to expect. If you need a class for you functionality, create a separate class that the task uses instead. |
Perhaps #3874 is related. |
closing in favor of #3874 hope it's fixed |
I'm having a few problems with the new version of Celery. It won't discover class based tasks.
Here' my conf and versions:
Versions
Installed celery with
pip install -U celery
then installed redis,pip install redis
.Tasks:
Basically I defined a master base task class, that makes sense for us. It does some setup and it will depend on the same stuff. I've imported this BaseTask class and ran the worker.
Steps to reproduce
celery -A scout worker -l info
Output:
Expected behavior
The class based tasks should also be picked up by celery. When I try to delegate a task to Celery, it will refuse it, because it's not registered. Note that the regular function based task is properly picked up by celery.
The text was updated successfully, but these errors were encountered: