mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14729 jobs detail
This commit is contained in:
parent
a7b2fe4fb2
commit
b18453e760
@ -1,5 +1,7 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import A # alias for Accessor
|
from django_tables2.utils import A # alias for Accessor
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.html import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from netbox.tables import NetBoxTable, columns
|
from netbox.tables import NetBoxTable, columns
|
||||||
@ -29,7 +31,7 @@ class BackgroundTasksTable(tables.Table):
|
|||||||
|
|
||||||
class BackgroundTasksQueueTable(tables.Table):
|
class BackgroundTasksQueueTable(tables.Table):
|
||||||
# id = tables.LinkColumn("core:background_tasks_queues", args=[A("index")], verbose_name=_("ID"))
|
# id = tables.LinkColumn("core:background_tasks_queues", args=[A("index")], verbose_name=_("ID"))
|
||||||
id = tables.Column(verbose_name=_("ID"))
|
id = tables.Column(empty_values=(), verbose_name=_("ID"))
|
||||||
created_at = tables.Column(verbose_name=_("Created"))
|
created_at = tables.Column(verbose_name=_("Created"))
|
||||||
enqueued_at = tables.Column(verbose_name=_("Enqueued"))
|
enqueued_at = tables.Column(verbose_name=_("Enqueued"))
|
||||||
ended_at = tables.Column(verbose_name=_("Ended"))
|
ended_at = tables.Column(verbose_name=_("Ended"))
|
||||||
@ -41,6 +43,12 @@ class BackgroundTasksQueueTable(tables.Table):
|
|||||||
'class': 'table table-hover object-list',
|
'class': 'table table-hover object-list',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def render_id(self, value, record):
|
||||||
|
return mark_safe('<a href=' + reverse(
|
||||||
|
"core:background_tasks_job_detail",
|
||||||
|
args=[self.queue_index, value]) + '>' + value + '</a>'
|
||||||
|
)
|
||||||
|
|
||||||
def render_status(self, value, record):
|
def render_status(self, value, record):
|
||||||
return record.get_status
|
return record.get_status
|
||||||
|
|
||||||
@ -49,3 +57,7 @@ class BackgroundTasksQueueTable(tables.Table):
|
|||||||
return record.func_name
|
return record.func_name
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return repr(e)
|
return repr(e)
|
||||||
|
|
||||||
|
def __init__(self, queue_index, *args, **kwargs):
|
||||||
|
self.queue_index = queue_index
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -28,6 +28,7 @@ urlpatterns = (
|
|||||||
# Background Tasks
|
# Background Tasks
|
||||||
path('background-tasks/', views.BackgroundTasksListView.as_view(), name='background_tasks_list'),
|
path('background-tasks/', views.BackgroundTasksListView.as_view(), name='background_tasks_list'),
|
||||||
path('background-tasks/queues/<int:queue_index>/', views.BackgroundTasksQueueListView.as_view(), name='background_tasks_queues'),
|
path('background-tasks/queues/<int:queue_index>/', views.BackgroundTasksQueueListView.as_view(), name='background_tasks_queues'),
|
||||||
|
path('background-tasks/queues/<int:queue_index>/<str:job_id>/', views.BackgroundTasksJobDetailView.as_view(), name='background_tasks_job_detail'),
|
||||||
|
|
||||||
# Config revisions
|
# Config revisions
|
||||||
path('config-revisions/', views.ConfigRevisionListView.as_view(), name='configrevision_list'),
|
path('config-revisions/', views.ConfigRevisionListView.as_view(), name='configrevision_list'),
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden, Http404
|
||||||
from django_rq.queues import get_queue_by_index
|
from django_rq.queues import get_queue_by_index
|
||||||
from django_rq.utils import get_scheduler_statistics, get_statistics
|
from django_rq.utils import get_scheduler_statistics, get_statistics
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
from netbox.config import get_config, PARAMS
|
from netbox.config import get_config, PARAMS
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from netbox.views.generic.base import BaseObjectView
|
from netbox.views.generic.base import BaseObjectView
|
||||||
|
from rq.exceptions import NoSuchJobError
|
||||||
|
from rq.job import Job as RQ_Job
|
||||||
from utilities.utils import count_related
|
from utilities.utils import count_related
|
||||||
from utilities.views import ContentTypePermissionRequiredMixin, register_model_view
|
from utilities.views import ContentTypePermissionRequiredMixin, register_model_view
|
||||||
from . import filtersets, forms, tables
|
from . import filtersets, forms, tables
|
||||||
@ -262,8 +263,25 @@ class BackgroundTasksQueueListView(LoginRequiredMixin, View):
|
|||||||
else:
|
else:
|
||||||
jobs = []
|
jobs = []
|
||||||
|
|
||||||
table = tables.BackgroundTasksQueueTable(jobs)
|
table = tables.BackgroundTasksQueueTable(data=jobs, queue_index=queue_index)
|
||||||
return render(request, 'core/background_tasks_queue.html', {
|
return render(request, 'core/background_tasks_queue.html', {
|
||||||
'table': table,
|
'table': table,
|
||||||
'queue': queue,
|
'queue': queue,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class BackgroundTasksJobDetailView(LoginRequiredMixin, View):
|
||||||
|
|
||||||
|
def get(self, request, queue_index, job_id):
|
||||||
|
queue_index = int(queue_index)
|
||||||
|
queue = get_queue_by_index(queue_index)
|
||||||
|
|
||||||
|
try:
|
||||||
|
job = RQ_Job.fetch(job_id, connection=queue.connection, serializer=queue.serializer)
|
||||||
|
except NoSuchJobError:
|
||||||
|
raise Http404("Couldn't find job with this ID: %s" % job_id)
|
||||||
|
|
||||||
|
return render(request, 'core/background_tasks_job.html', {
|
||||||
|
'queue': queue,
|
||||||
|
'job': job,
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user