mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-01 14:58:12 +08:00
Rerun successful tasks (#99)
* Move logic that resubmits a task and then deletes the original into an action function that can be used for both failure and success resubmission. * Use the resubmit_task action in the FailAdmin. * Add the resubmit_task action to the TaskAdmin class. * Update resubmit failure test to reflect using the new resubmit action. * Add a test for resubmitting successful tasks. --------- Co-authored-by: Scott Pashley
This commit is contained in:
co-authored by
Scott Pashley
parent
f8321e7f54
commit
23c06a38eb
+20
-12
@@ -10,10 +10,29 @@ from django_q.models import Failure, OrmQ, Schedule, Success, Task
|
||||
from django_q.tasks import async_task
|
||||
|
||||
|
||||
def resubmit_task(model_admin, request, queryset):
|
||||
"""Submit selected tasks back to the queue."""
|
||||
for task in queryset:
|
||||
async_task(
|
||||
task.func,
|
||||
*task.args or (),
|
||||
hook=task.hook,
|
||||
group=task.group,
|
||||
cluster=task.cluster,
|
||||
**task.kwargs or {},
|
||||
)
|
||||
if isinstance(model_admin, FailAdmin):
|
||||
task.delete()
|
||||
|
||||
|
||||
resubmit_task.short_description = _("Resubmit selected tasks to queue")
|
||||
|
||||
|
||||
class TaskAdmin(admin.ModelAdmin):
|
||||
"""model admin for success tasks."""
|
||||
|
||||
list_display = ("name", "group", "func", "cluster", "started", "stopped", "time_taken")
|
||||
actions = [resubmit_task]
|
||||
|
||||
def has_add_permission(self, request):
|
||||
"""Don't allow adds."""
|
||||
@@ -33,17 +52,6 @@ class TaskAdmin(admin.ModelAdmin):
|
||||
return list(self.readonly_fields) + [field.name for field in obj._meta.fields]
|
||||
|
||||
|
||||
def retry_failed(FailAdmin, request, queryset):
|
||||
"""Submit selected tasks back to the queue."""
|
||||
for task in queryset:
|
||||
async_task(task.func, *task.args or (), hook=task.hook,
|
||||
group=task.group, cluster=task.cluster, **task.kwargs or {})
|
||||
task.delete()
|
||||
|
||||
|
||||
retry_failed.short_description = _("Resubmit selected tasks to queue")
|
||||
|
||||
|
||||
class FailAdmin(admin.ModelAdmin):
|
||||
"""model admin for failed tasks."""
|
||||
|
||||
@@ -53,7 +61,7 @@ class FailAdmin(admin.ModelAdmin):
|
||||
"""Don't allow adds."""
|
||||
return False
|
||||
|
||||
actions = [retry_failed]
|
||||
actions = [resubmit_task]
|
||||
search_fields = ("name", "func", "group")
|
||||
list_filter = ("group", "cluster")
|
||||
readonly_fields = []
|
||||
|
||||
Reference in New Issue
Block a user