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
Update the docs to make it clear tasks must be published from within the Django context #77
Comments
I'll see if i can make the docs a bit clearer, but in general the modules containing your tasks should be kept in an app directory. What's in your carrot_test file exactly? |
Hey, thanks for getting back to me! Here's my file including the comments so that you can see what I tried:
As you can see I did figure out that I needed to make the function available to django and I was able to get things working. Also worth noting that if I uncomment the name==main bit I don't get the task scheduled simply by importing the file anymore. I was thinking about making a PR for a management command for something like |
Sure, that could work. You could leverage the publish_task method in carrot.utilities which validates import paths before publishing a task. Would you have the same method start the consumer as well, or just work on the basis that it would already be running? |
Yeah I'll take a stab at it and see how I do. Thanks for the feedback! |
Docs have been updated for 1.2.0 |
I'm just getting started with carrot on a new project after having fairly extensive experience with celery. A lot of the "why carrot?" explanations resonated with me, so thanks very much for making this!
I created a
carrot_test.py
file in the root of my django project, next tomanage.py
and then tried to run it. When I did, I saw this:Is this the end of the world? Not at all, I've seen similar when trying to run things that need django on the path, so I dug around on the 'net and found this stanza:
Then when I run it, it seems to work! This is great!
But when I check my
carrot.log
I see this:It seems like there's some confusion about where/how carrot should be looking to find the function itself.
I was able to solve my problem by putting the task into a module that was already in the django path, importing it in
carrot_test.py
and then executing and that worked. But it was a bit of a challenge to figure out what would work and what wouldn't. Initially the only way I figured out how to get it to work was by firing up a python shell and importingcarrot_test
and I just happened to see that got the task run successfully without erroring. It was a confusing first hour until I understood what was going on.If you're triggering jobs from a view function and your tasks are already in packages that are on the django path I don't think you'll run into any of these problems. But when getting started for the very first time I at least tend to try the simplest thing like firing up a single-purpose file.
The text was updated successfully, but these errors were encountered: