django-tasks
django-tasks copied to clipboard
Delete and retry tasks through Django Admin
I found it super useful to be able to delete and to reschedule tasks through the Django Admin.
Update – this PR now adds two admin actions:
- Reenqueue: change the
statusof the selected tasks toNEW, so they will be executed again. - Duplicate: clone the selected tasks, leaving the old ones unchanged, and the new ones as
NEW, with no result or started/finished timestamps.
@RealOrangeOne Any plans of merging this soon? We would need this. :)
@Alwinator it's a draft PR with failing tests and conflicts. It's not as simple as just "merging" it I'm afraid. Once it's ready, it'll absolutely be merged.
Thank you! @mgax Any plans to finish your request? :)
Sure, I'd forgotten about this, I'll see about rebasing and fixing the tests.
I've rebased the branch. I'm not sure why the CI is failing now. I've narrowed it down to this change: https://github.com/mgax/django-tasks/commit/36d3d3815ed63c5e7619047a0bca2154e3d58306. It looks like the failures are flaky, and I'm guessing that the test somehow causes other tests to fail. But I can't reproduce it locally; for me (MacOS 15.1.1, Python 3.13, Django 5.0) just test reliably works.
@mgax Any updates on this topic? 😇
Sharing a quick snippet if someone is trying to reenqueue stale RUNNING tasks:
from django_tasks.backends.database.models import DBTaskResult, ResultStatus
DBTaskResult.objects.filter(status=ResultStatus.RUNNING).update(status=ResultStatus.NEW)
Update: Bonus management command!
# python manage.py reset_running_tasks
from django.core.management.base import BaseCommand
from django_tasks.backends.database.models import DBTaskResult, ResultStatus
class Command(BaseCommand):
help = 'Resets all DBTaskResult objects with status RUNNING to status NEW.'
def handle(self, *args, **options):
updated = DBTaskResult.objects.filter(status=ResultStatus.RUNNING).update(status=ResultStatus.NEW)
self.stdout.write(self.style.SUCCESS(f'Successfully reset {updated} running tasks to NEW.'))
hi! Any updates? :)
@NicolasArnouts https://justinmayer.com/posts/any-updates/