django-tasks icon indicating copy to clipboard operation
django-tasks copied to clipboard

Delete and retry tasks through Django Admin

Open mgax opened this issue 1 year ago • 6 comments
trafficstars

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 status of the selected tasks to NEW, 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.

mgax avatar Aug 01 '24 00:08 mgax

@RealOrangeOne Any plans of merging this soon? We would need this. :)

Alwinator avatar Dec 09 '24 09:12 Alwinator

@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.

RealOrangeOne avatar Dec 10 '24 10:12 RealOrangeOne

Thank you! @mgax Any plans to finish your request? :)

Alwinator avatar Dec 10 '24 11:12 Alwinator

Sure, I'd forgotten about this, I'll see about rebasing and fixing the tests.

mgax avatar Dec 12 '24 12:12 mgax

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 avatar Dec 23 '24 16:12 mgax

@mgax Any updates on this topic? 😇

Alwinator avatar Apr 28 '25 12:04 Alwinator

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.')) 

djpeacher avatar Jun 11 '25 10:06 djpeacher

hi! Any updates? :)

NicolasArnouts avatar Jul 31 '25 07:07 NicolasArnouts

@NicolasArnouts https://justinmayer.com/posts/any-updates/

djpeacher avatar Jul 31 '25 14:07 djpeacher