[Update] 增加task最大允许事件,并设置命令最大运行时间为60s

This commit is contained in:
ibuler
2019-03-27 11:12:34 +08:00
parent afe9471aa2
commit 6e7446f530
8 changed files with 54 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import subprocess
from django.conf import settings
from celery import shared_task, subtask
from celery.exceptions import SoftTimeLimitExceeded
from django.utils import timezone
from common.utils import get_logger, get_object_or_none
@@ -38,11 +39,14 @@ def run_ansible_task(tid, callback=None, **kwargs):
logger.error("No task found")
@shared_task
@shared_task(soft_time_limit=60)
def run_command_execution(cid, **kwargs):
execution = get_object_or_none(CommandExecution, id=cid)
if execution:
execution.run()
try:
execution.run()
except SoftTimeLimitExceeded:
print("HLLL")
else:
logger.error("Not found the execution id: {}".format(cid))

View File

@@ -82,6 +82,7 @@
<script>
var zTree, show = 0;
var systemUserId = null;
var treeUrl = "{% url 'api-perms:my-nodes-assets-as-tree' %}?cache_policy=1";
function initTree() {
var setting = {
@@ -110,14 +111,17 @@ function initTree() {
onCheck: onCheck
}
};
var url = "{% url 'api-perms:my-nodes-assets-as-tree' %}?cache_policy=1";
if (systemUserId) {
url += '&system_user=' + systemUserId
url = treeUrl + '&system_user=' + systemUserId
}
$.get(url, function(data, status){
$.fn.zTree.init($("#assetTree"), setting, data);
zTree = $.fn.zTree.getZTreeObj("assetTree");
rootNodeAddDom(zTree, function () {
treeUrl = treeUrl.replace('cache_policy=1', 'cache_policy=2');
initTree();
});
});
}
@@ -250,7 +254,8 @@ function execute() {
method: 'POST',
flash_message: false,
success: function (resp) {
term.write("{% trans 'Pending' %}" + "...\r\n");
var msg = "{% trans 'Pending' %}";
term.write(msg + "...\r\n");
log_url = resp.log_url;
int = setInterval(function () {
writeExecutionOutput()

View File

@@ -5,6 +5,7 @@ from django.utils.translation import ugettext as _
from django.conf import settings
from django.views.generic import ListView, TemplateView
from common.permissions import AdminUserRequiredMixin, LoginRequiredMixin
from common.mixins import DatetimeSearchMixin
from ..models import CommandExecution
from ..forms import CommandExecutionForm
@@ -15,7 +16,7 @@ __all__ = [
]
class CommandExecutionListView(DatetimeSearchMixin, ListView):
class CommandExecutionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
template_name = 'ops/command_execution_list.html'
model = CommandExecution
paginate_by = settings.DISPLAY_PER_PAGE
@@ -50,7 +51,7 @@ class CommandExecutionListView(DatetimeSearchMixin, ListView):
return super().get_context_data(**kwargs)
class CommandExecutionStartView(TemplateView):
class CommandExecutionStartView(LoginRequiredMixin, TemplateView):
template_name = 'ops/command_execution_create.html'
form_class = CommandExecutionForm