-
Notifications
You must be signed in to change notification settings - Fork 206
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
Tasks are not getting added to database #19
Comments
Hi,
|
I'm also seeing this as well. |
I'm new to Celery and I think there's a lack of proper documentation on how to use this package. I also can't get my task results stored. When I do
I get
Update: I got it working this way:
Then in a shell:
|
If you're using CeleryBeat remind it behaves just as a scheduler. So a
worker is still needed for the tasks to be consumed.
This is what trapped me when reading the docs for Django-related usage.
Stefano Quaranta
Il 27 mag 2017 4:45 AM, "Andrey Panin" <[email protected]> ha
scritto:
I'm new to Celery and I think there's a lack of proper documentation on how
to use this package. It only describes how to install, but not how to use.
I also can't get my task results stored.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#19 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABL8qpTj47OnglSv6yNPzZAg0VmWVjTtks5r945JgaJpZM4NMUfm>
.
…--
[image: Phpower]Reduce your footprint. Only print this email if necessary.
This message, may contain confidential and/or privileged information. If
you are not the addressee or authorized to receive this for the addressee,
you must not use, copy, disclose or take any action based on this message
or any information herein. If you have received this message in error,
please advise the sender immediately by reply e-mail and delete this
message.
|
Docs are bit confusing for new beginners. I also got stuck. |
@anapana My guess is that you're looking at the wrong DB or at the wrong table. Check |
@andreypanin , thank you! Yes, just figured that out, I was looking into the wrong table, so deleted my comment. I'm having the same issue as people here, when |
Tried all of the proposed solutions and nothing worked, I'm also assuming that I'm using newer version of packages, since docs are outdated.
is wrong and it has to be
since celery is looking for the prefix trying to find the right backend class: https://github.com/celery/celery/blob/master/celery/app/backends.py My requirements:
Now I made it work, but it's ugly. If I explicitly pass the backend class to task decorator (for writing) and to # tasks.py
from project.celery import app
from django_celery_results.backends import DatabaseBackend
@app.task(name="task_name", backend=DatabaseBackend(app, url='sqlite:///django-db.sqlite3'))
def task():
return 2+2 # views.py
from celery.result import AsyncResult
...
from django_celery_results.models import TaskResult
from django_celery_results.backends import DatabaseBackend
from project.celery import app
from project.main.tasks import task
class CeleryTestPage(View):
def get(self, request):
t = task.delay()
t_result = AsyncResult(t.task_id, backend=DatabaseBackend(app, url='sqlite:///db.sqlite3'))
HttpResponse(t_result.status)
class CeleryResults(View):
def get(self, request):
tasks = TaskResult.objects.all() # this now works
return HttpResponse(tasks) So I'm assuming Now my question is: if celery itself already writes data to The schema of those two tables are very similar:
Am I missing something? |
@anapana Hm maybe this is being loaded somewhere else, but if |
same issue here, django_celery_results_taskresult empty. |
Had the same issue, what worked for me is: CELERY_RESULT_BACKEND = 'db+sqlite:///django-db' thanks @anapana Linux-4.10.0-32-generic-x86_64-with-Ubuntu-16.04-xenial 2017-08-22 12:06:18 |
I'm using MariaDB and CELERY_RESULT_BACKEND = 'django-db' worked for me. However, the entry is only put in the table AFTER the job has finished, with success or not. Would it make sense to update the table right after the job is scheduled? Otherwise the "pending" status doesn't seem to be useful... |
Generally, all works fine with sqlite and 'django-db'. All you need is to set it in settings:
And as was mentioned above, you need to run celery worker to make it work: For test purposes, you can run any task from python shell, and you will see this task in worker log and also new entry in django_celery_results_taskresult table in your database or in django-admin panel. PS: I used SQLite and 'django-db' settings, so all above from my experience. |
It works as expected with Tested on a devel box with |
I am facing a similar issue. I am trying to get the task status after submitting a task.
My Django app crashes here with an error msg:
Does anyone here know what I am doing wrong? And how to fix it? In settings.py I have following:
I have run the command |
I am also facing the same issue with django_celery_results_taskresult created after migrate but always empty. This is the only way I found to make the results backend not empty ( PS: I have no errors or crashes |
Did anyone figure out a solution? I am facing the similar issue. |
May or may not be similar to the issues of others, but my mistake was that my app was not loading the celery settings from my
and then decorating my tasks with In order to load the celery settings from
After doing this, task results are now being stored in the database. |
Experiencing same issue, django 2.0.6 |
Hi, I'm experiencing exactly this same issue. Tasks only get added to the DB table once they are completed. Django 1.11.x. |
Same here, using old celery (3.1.25), django-celery-3.2.1. Tasks are added, but only once finished (success or failure). As a result i can't use state 'PENDING' and 'STARTED' as i did previously (it was working previously, but can't say which versions were used) |
Remove or Comment if you have these lines in settings file.
|
i also has same problem, my database is postgresql and finally i found that when add
|
Same issue here, did anyone figure out a solution? |
In my case with a postgresql database and with @findsomeoneyys configuration tips, results are added to the database but only when the processes are finished. celery-4.2.1 |
+1 I am pretty sure I was using celery==4.2.1 |
I have the same issue with PostgreSQL and a Redis broker. My tasks are added to the Task result table only on success or failure. Any update?
django-celery-results==1.0.4 The only other status I can get is |
After facing the same problem and inspecting this project's code, it looks like the fault is on celery configuration, as the backend method to store a task's results is not called until the end of the task. |
This is likely the solution for many of the people in this thread. Even if you explicitly write the arguments in the constructor, you still need to call |
which version you are using? |
why was this issue closed? is the problem fixed? |
If I had to guess, it's because all the issues were related to specific implementations, and not an issue with django-celery-results. I just installed it by following the docs, and no issue. Just make sure you restart your celery workers afterwards. might try posting on stackoverlow |
Did someone find the problems of this issue ? |
@dangelsaurus |
I had the problem where the entries were not appearing at all on the django_celery_results_taskresult table. The problem was in the Django settings file. In VSCode launch.json I have a postgres db set up for my local dev env, however the fallback settings in Django was set to a local sqlite DB.
This does make sense if you think about it, you have to make the celery worker aware of your local environment variables (this is my next challenge...presumably doing something with the args in launch.json) What is unfortunate is that it fails silently: my sqlite file doesn't exist, so it would be awesome for debugging if the celery_results package could report this in the terminal window. |
I think VSCode supports |
As @plachira mentions here, try to either set both This is a bit unfortunate though, "eager mode" is very useful when debugging issues. Perhaps someone else could shed some light on how to run tasks synchronously and still be able to use |
i managed to get it working on windows by adding |
Adding |
@auvipy Have you considered making Without it on local with eager you get no results in the db table, and no output in the console unless you read directly Super confusing. |
would you mind sharing the improvement suggestion in the form of a PR? it will be easier for me to reasoning after see the code changed proposal |
Not directly linked to django-celery-results, but that might help... For those having issue with the tasks being added to database (postgressql or other) only after they are finished, I just wanted to add that this is normal behavior. According to Celery documentation, tasks initial "STARTED" state are not tracked. This behavior can be changed:
It tooks me 2hrs to figure this out 😝 |
as @batzkass mentioned here adding @batzkass thanks brother |
|
Hi,
I have followed this link: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#django-celery-results-using-the-django-orm-cache-as-a-result-backend
to set up django-celery-results for my project. Migrations are running fine and i can see table
django_celery_results_taskresult
got created.The problem is when i try to execute a task, it runs fine but the table i mentioned above didn't get populated.
I have put
CELERY_RESULT_BACKEND = 'django-db'
and have placeddjango_celery_results
in my INSTALLED_APPS. There is no error in logs either. Can anyone give me hint what i am doing wrong? Or guide me how can i debug this issue?The text was updated successfully, but these errors were encountered: