mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-23 13:36:35 +00:00
Pagination for scheduled tasks
Keep showing running and errors on every page.
This commit is contained in:
parent
b78075557a
commit
2d4e23a8d7
@ -743,6 +743,7 @@ class TasksView(ListView):
|
|||||||
|
|
||||||
template_name = 'sync/tasks.html'
|
template_name = 'sync/tasks.html'
|
||||||
context_object_name = 'tasks'
|
context_object_name = 'tasks'
|
||||||
|
paginate_by = settings.TASKS_PER_PAGE
|
||||||
messages = {
|
messages = {
|
||||||
'reset': _('All tasks have been reset'),
|
'reset': _('All tasks have been reset'),
|
||||||
}
|
}
|
||||||
@ -757,17 +758,24 @@ class TasksView(ListView):
|
|||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Task.objects.all().order_by('run_at')
|
_ordering = getattr(settings,
|
||||||
|
'BACKGROUND_TASK_PRIORITY_ORDERING',
|
||||||
|
'DESC'
|
||||||
|
)
|
||||||
|
return Task.objects.all().order_by(
|
||||||
|
f"{'-' if 'ASC' != _ordering else ''}priority",
|
||||||
|
'run_at'
|
||||||
|
)
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
data = super().get_context_data(*args, **kwargs)
|
data = super().get_context_data(*args, **kwargs)
|
||||||
data['message'] = self.message
|
data['message'] = self.message
|
||||||
|
queryset = self.get_queryset()
|
||||||
data['running'] = []
|
data['running'] = []
|
||||||
data['errors'] = []
|
data['errors'] = []
|
||||||
data['scheduled'] = []
|
data['scheduled'] = []
|
||||||
queryset = self.get_queryset()
|
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
for task in queryset:
|
for task in queryset.filter(locked_at__isnull=False):
|
||||||
# There was broken logic in `Task.objects.locked()`, work around it.
|
# There was broken logic in `Task.objects.locked()`, work around it.
|
||||||
# With that broken logic, the tasks never resume properly.
|
# With that broken logic, the tasks never resume properly.
|
||||||
# This check unlocks the tasks without a running process.
|
# This check unlocks the tasks without a running process.
|
||||||
@ -795,6 +803,21 @@ class TasksView(ListView):
|
|||||||
data['errors'].append(task)
|
data['errors'].append(task)
|
||||||
else:
|
else:
|
||||||
data['scheduled'].append(task)
|
data['scheduled'].append(task)
|
||||||
|
for task in data['tasks']:
|
||||||
|
obj, url = map_task_to_instance(task)
|
||||||
|
if not obj:
|
||||||
|
continue
|
||||||
|
already_added = (
|
||||||
|
task in data['running'] or
|
||||||
|
task in data['errors'] or
|
||||||
|
task in data['scheduled']
|
||||||
|
)
|
||||||
|
if already_added:
|
||||||
|
continue
|
||||||
|
setattr(task, 'instance', obj)
|
||||||
|
setattr(task, 'url', url)
|
||||||
|
setattr(task, 'run_now', task.run_at < now)
|
||||||
|
data['scheduled'].append(task)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user