-
-
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
Support for Django Model methods as tasks. #2600
Conversation
Changes Unknown when pulling 59d5069 on alexhayes:feature/django-model-method-task into * on celery:3.1*. |
Commit e3650bf has a working I'm working on a potential solution. |
What's the status here? |
I don't think this will be merged, since @ask is saying that task methods are failed experience (and I'm completely agree with him). |
Do you have an alternative implementation? |
Current status is I was waiting on input as to if task methods would definitely be removed in 3.2. I've spoken to @ask and he says that they won't be removed if the bugs can be sorted out. So I don't forget...
|
I'm closing this as I have created django-cereal which is a much better solution. There are still a number of other issues, such as #2137, when using task methods but these aren't really related to this issue. My focus now will be to fix issues related to task methods so they can be retained in 3.2. |
I'm submitting this PR more for review and suggestions for possible future inclusion.
Essentially I wanted a way to easily turn Django Model methods into tasks.
Up until now I've used
celery.contrib.methods.task
and a @refresh decorator to ensure I don't have a stale model instance. However this approach meant the entire model is serialized and sent across the wire, obviously this is not very efficient and completely unnecessary considering that you then refresh the model in the worker... Obviously the solution outlined in the docs gets around both these issues however when you have an application that relies heavily on methods in models and those methods need to be turned into tasks, creating tasks for each is not very DRY and a pain when refactoring.Thus, I wanted a solution that would only publish the minimum information required to the broker and using this data get a refresh model instance in the worker. The
@model_task
decorator achieves this by using base classDjangoModelBaseTask
that relies on some slight refactoring ofTask
internals.My thoughts/questions/comments thus far;
Task
an acceptable approach?augment_args_for_run
andaugment_args_for_send
augment_args_for_run
incelery/app/trace.py
- note that previously it wasn't checking forself.__self__
but now it will be. Will this be a problem? Note, all tests are passing on python 2.7 & 3.4.celery.canvas.Signature
.from django.db.models.loading import get_model
occurs withinDjangoModelBaseTask.augment_args_for_run
so that an import error does not occur when building docs - not ideal...I'd be happy to break
DjangoModelBaseTask
out into a separate project/repository which would get around the requirement for Django however it obviously relies on the slight refactoring ofTask
- it's also something that I imagine a lot of other users could benefit from (frankly, I can't believe I'm the first person to think of this...).