Comments (18)
I reduced the task to:
@background
def reindex(a, b):
print('done')
This works in python 2 when running the process_tasks
command. In python 3 it is silent. Num attempts isn't increased.
I'll create a django project from scratch in python 3 to see if I can reproduce in the simplest state.
from django-background-tasks.
settings.py
wasn't changed except for the addition of background_task
in the INSTALLED_APPS
list.
I've reproduced this using the latest from PyPI (django-background-tasks==1.0.5
).
from django-background-tasks.
Could you post your tasks.py please?
from django-background-tasks.
Regarding the logging mechanism, please see #16.
from django-background-tasks.
from background_task import background
from django.conf import settings
from django.core.mail import EmailMessage
from .search_indexes import full_index
@background
def reindex(config_slug, email_address):
subject = '{} reindex complete.'.format(config_slug.title())
msg = 'Reindex for {} finished successfully.'.format(config_slug)
try:
full_index(config_slug)
except Exception as e:
subject = '{} reindexing failed.'.format(config_slug.title())
msg = 'There was an error while reindexing {}:\n{}'.format(config_slug, e.args)
email = EmailMessage(subject, msg)
email.to = [email_address]
if settings.EMAIL_ADMINS_ON_REINDEX:
email.bcc = list(settings.ADMINS)
print('Sending email to {e}:\nSubject: {s}:\n{m}'.format(e=email_address, s=subject, m=msg))
email.send()
This task works fine in Python2.
from django-background-tasks.
Change the relative import (.search_indexes
) to an absolute one and it will work.
from django-background-tasks.
Made that change and it still isn't working.
The log says, INFO:root:Running Task(myapp.tasks.reindex)
when I trigger the task, but the task in the database doesn't get the attempted count incremented and it doesn't move to completed tasks.
from django-background-tasks.
Could you give it a try with an empty method to test if it's the background_task that has the Py3 issue or something different, eg something related to full_index
.
from django-background-tasks.
I'm not exactly sure what is going on but I did the following to reproduce and this time got an exception (in my actual project, it looks like it is just failing silently).
- Created a new django project (called
core
) in its own virtualenv with Python 3.4 and Django 1.7.10. - Installed
django-background-tasks
. - Created a
tasks.py
file with the simple task:
@background
def test():
print('done')
- Imported and ran the
test
task from the django shell. - Ran
./manage.py process_tasks
I get the following exception:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/background_task/management/commands/process_tasks.py", line 81, in handle
if not tasks.run_next_task():
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/background_task/tasks.py", line 107, in run_next_task
return self._runner.run_next_task(self)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/db/transaction.py", line 394, in inner
return func(*args, **kwargs)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/background_task/tasks.py", line 230, in run_next_task
self.run_task(tasks, task)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/django/db/transaction.py", line 394, in inner
return func(*args, **kwargs)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/background_task/tasks.py", line 220, in run_task
tasks.run_task(task.task_name, args, kwargs)
File "/home/chadgh/.virtualenvs/tmp-3b687c658fb88a5/lib/python3.4/site-packages/background_task/tasks.py", line 100, in run_task
proxy_task = self._tasks[task_name]
KeyError: 'core.tasks.test'
I also attempted this whole process by adding the task calling in a view and hitting the view in a running runserver
, then running the process_tasks
command. I got the exact same result.
from django-background-tasks.
We will try to reproduce this. Did you have specified something in the settings.py
and are you using the latest release? Thanks for the additional information @chadgh .
from django-background-tasks.
I have the same issue and I created an example django project to reproduce this:
https://github.com/hnakamur/django-background-tasks-example
I attached results for Python 2 and Python 3 to the README at this page.
@philippeowagner Could you have a look at the example above? Thanks!
from django-background-tasks.
We fixed the bug, could you @hnakamur @chadgh please give a try to django-background-tasks-1.0.7? It's on PyPI. Thanks.
from django-background-tasks.
@philippeowagner I tried django-background-tasks-1.0.7 with Python 3.4.3 and confirmed it works correctly.
collinmutembei/django-background-tasks-example@feac03e
Thanks for the quick fix!
from django-background-tasks.
BTW @hnakamur you example project is awesome and could help noobies to set up django-background-tasks. It should be mentioned in the README. Is this in your interest as well (or will you drop it as it's fixed?)?
from django-background-tasks.
@philippeowagner It's my pleasure! Actually I am a newbie too and thought it is helpful if there is an example project using django-background-tasks.
from django-background-tasks.
Great @hnakamur , I will mention it in the README. :-)
from django-background-tasks.
@chadgh feel free if you still perform any issues.
from django-background-tasks.
Looks like it is working now. Thanks @philippeowagner @hnakamur for the fix!
from django-background-tasks.
Related Issues (20)
- Async Background still runs tasks linearly instead of Parallel HOT 2
- Run tasks individually
- best way to start repeating tasks and question about failing
- manage.py process_tasks not picking tasks w Django 3.2 HOT 2
- What happens if I add multiple process_tasks workers?
- BACKGROUND_TASK_RUN_ASYNC = True not working
- Not supported in Django 4.0 HOT 4
- Repeatedly get 'Failed to retrieve tasks. Database unreachable.' error message.
- Change "has error" to "successful" for UI
- Tasks Run Multiple Times because of Error
- Add individual `max_run_time`option at task level.
- Is this project still maintained? HOT 3
- Do I need to run process_tasks to start tasks? HOT 3
- Does django background tasks slow down my site? HOT 1
- ModuleNotFoundError: No module named 'background-task'
- Background task running twice. HOT 2
- CHANGE DEFAULT DB CONNECTION
- How can I detect the task errors?
- does not work anymore in Python 12 HOT 5
- Repetitive task will stop working after max_attempts reached
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-background-tasks.