fix: 终断任务时接口报错

pull/12720/head
wangruidong 2024-02-26 18:04:21 +08:00 committed by Bryan
parent 7517e77af9
commit e71e335f5c
5 changed files with 61 additions and 14 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:c9446906e12d6db2687753ded172353a7df3b087db0d0d848bf10158d611fc1b oid sha256:d04781f4f0b0de3ac5f707febb222e239553d6103bca0cec41ab2fd5ab044571
size 171615 size 173799

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-26 18:02+0800\n" "POT-Creation-Date: 2024-02-27 16:09+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -4077,11 +4077,11 @@ msgstr "タスクは存在しません"
msgid "Task {} args or kwargs error" msgid "Task {} args or kwargs error"
msgstr "タスク実行パラメータエラー" msgstr "タスク実行パラメータエラー"
#: ops/api/job.py:132 #: ops/api/job.py:135
msgid "Duplicate file exists" msgid "Duplicate file exists"
msgstr "重複したファイルが存在する" msgstr "重複したファイルが存在する"
#: ops/api/job.py:137 #: ops/api/job.py:140
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"File size exceeds maximum limit. Please select a file smaller than {limit}MB" "File size exceeds maximum limit. Please select a file smaller than {limit}MB"
@ -4089,6 +4089,11 @@ msgstr ""
"ファイルサイズが最大制限を超えています。{limit}MB より小さいファイルを選択し" "ファイルサイズが最大制限を超えています。{limit}MB より小さいファイルを選択し"
"てください。" "てください。"
#: ops/api/job.py:204
msgid ""
"The task is being created and cannot be interrupted. Please try again later."
msgstr "タスクを作成中で、中断できません。後でもう一度お試しください。"
#: ops/api/playbook.py:39 #: ops/api/playbook.py:39
msgid "Currently playbook is being used in a job" msgid "Currently playbook is being used in a job"
msgstr "現在プレイブックは1つのジョブで使用されています" msgstr "現在プレイブックは1つのジョブで使用されています"
@ -7294,30 +7299,37 @@ msgid "Container Ports"
msgstr "コンテナポート" msgstr "コンテナポート"
#: terminal/session_lifecycle.py:30 #: terminal/session_lifecycle.py:30
#, python-format
msgid "Connect to asset %s success" msgid "Connect to asset %s success"
msgstr "アセット %s への接続に成功しました" msgstr "アセット %s への接続に成功しました"
#: terminal/session_lifecycle.py:38 #: terminal/session_lifecycle.py:38
#, python-format
msgid "Connect to asset %s finished: %s" msgid "Connect to asset %s finished: %s"
msgstr "アセット %s への接続が完了しました: %s" msgstr "アセット %s への接続が完了しました: %s"
#: terminal/session_lifecycle.py:48 #: terminal/session_lifecycle.py:48
#, python-format
msgid "User %s create share link" msgid "User %s create share link"
msgstr "ユーザー %s が共有リンクを作成しました" msgstr "ユーザー %s が共有リンクを作成しました"
#: terminal/session_lifecycle.py:57 #: terminal/session_lifecycle.py:57
#, python-format
msgid "User %s join session" msgid "User %s join session"
msgstr "ユーザー %s がセッションに参加しました" msgstr "ユーザー %s がセッションに参加しました"
#: terminal/session_lifecycle.py:69 #: terminal/session_lifecycle.py:69
#, python-format
msgid "User %s leave session" msgid "User %s leave session"
msgstr "ユーザー %s がセッションを離れました" msgstr "ユーザー %s がセッションを離れました"
#: terminal/session_lifecycle.py:81 #: terminal/session_lifecycle.py:81
#, python-format
msgid "User %s join to monitor session" msgid "User %s join to monitor session"
msgstr "ユーザー %s がモニターセッションに参加しました" msgstr "ユーザー %s がモニターセッションに参加しました"
#: terminal/session_lifecycle.py:93 #: terminal/session_lifecycle.py:93
#, python-format
msgid "User %s exit to monitor session" msgid "User %s exit to monitor session"
msgstr "ユーザー %s がモニターセッションを離れました" msgstr "ユーザー %s がモニターセッションを離れました"
@ -7330,6 +7342,7 @@ msgid "Replay successfully converted to MP4 format"
msgstr "リプレイが正常にMP4形式に変換されました" msgstr "リプレイが正常にMP4形式に変換されました"
#: terminal/session_lifecycle.py:121 #: terminal/session_lifecycle.py:121
#, python-format
msgid "Replay failed to convert to MP4 format: %s" msgid "Replay failed to convert to MP4 format: %s"
msgstr "リプレイのMP4形式への変換に失敗しました: %s" msgstr "リプレイのMP4形式への変換に失敗しました: %s"
@ -7342,10 +7355,11 @@ msgid "Replay successfully uploaded"
msgstr "リプレイが正常にアップロードされました" msgstr "リプレイが正常にアップロードされました"
#: terminal/session_lifecycle.py:145 #: terminal/session_lifecycle.py:145
#, python-format
msgid "Replay failed to upload: %s" msgid "Replay failed to upload: %s"
msgstr "リプレイのアップロードに失敗しました: %s" msgstr "リプレイのアップロードに失敗しました: %s"
#: terminal/session_lifecycle.py:152" #: terminal/session_lifecycle.py:152
msgid "connect failed" msgid "connect failed"
msgstr "接続に失敗しました" msgstr "接続に失敗しました"
@ -8632,7 +8646,7 @@ msgstr "そして"
msgid "Or" msgid "Or"
msgstr "または" msgstr "または"
#: xpack/plugins/cloud/manager.py:56 #: xpack/plugins/cloud/manager.py:57
msgid "Account unavailable" msgid "Account unavailable"
msgstr "利用できないアカウント" msgstr "利用できないアカウント"

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:78af89ae300362f26852652ebd1abcf24885a2c2ab1154baba2a4a20f16e2817 oid sha256:e66a6fa05d25f1c502f95001b5ff0d0a310affd32eac939fd7b840845028074f
size 140688 size 142298

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: JumpServer 0.3.3\n" "Project-Id-Version: JumpServer 0.3.3\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-26 18:02+0800\n" "POT-Creation-Date: 2024-02-27 16:09+0800\n"
"PO-Revision-Date: 2021-05-20 10:54+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n"
"Last-Translator: ibuler <ibuler@qq.com>\n" "Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: JumpServer team<ibuler@qq.com>\n" "Language-Team: JumpServer team<ibuler@qq.com>\n"
@ -4028,16 +4028,21 @@ msgstr "任务 {} 不存在"
msgid "Task {} args or kwargs error" msgid "Task {} args or kwargs error"
msgstr "任务 {} 执行参数错误" msgstr "任务 {} 执行参数错误"
#: ops/api/job.py:132 #: ops/api/job.py:135
msgid "Duplicate file exists" msgid "Duplicate file exists"
msgstr "存在同名文件" msgstr "存在同名文件"
#: ops/api/job.py:137 #: ops/api/job.py:140
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"File size exceeds maximum limit. Please select a file smaller than {limit}MB" "File size exceeds maximum limit. Please select a file smaller than {limit}MB"
msgstr "文件大小超过最大限制。请选择小于 {limit}MB 的文件。" msgstr "文件大小超过最大限制。请选择小于 {limit}MB 的文件。"
#: ops/api/job.py:204
msgid ""
"The task is being created and cannot be interrupted. Please try again later."
msgstr "正在创建任务,无法中断,请稍后重试。"
#: ops/api/playbook.py:39 #: ops/api/playbook.py:39
msgid "Currently playbook is being used in a job" msgid "Currently playbook is being used in a job"
msgstr "当前 playbook 正在作业中使用" msgstr "当前 playbook 正在作业中使用"
@ -7193,30 +7198,37 @@ msgid "Container Ports"
msgstr "容器端口" msgstr "容器端口"
#: terminal/session_lifecycle.py:30 #: terminal/session_lifecycle.py:30
#, python-format
msgid "Connect to asset %s success" msgid "Connect to asset %s success"
msgstr "连接资产 %s 成功" msgstr "连接资产 %s 成功"
#: terminal/session_lifecycle.py:38 #: terminal/session_lifecycle.py:38
#, python-format
msgid "Connect to asset %s finished: %s" msgid "Connect to asset %s finished: %s"
msgstr "连接资产 %s 结束: %s" msgstr "连接资产 %s 结束: %s"
#: terminal/session_lifecycle.py:48 #: terminal/session_lifecycle.py:48
#, python-format
msgid "User %s create share link" msgid "User %s create share link"
msgstr "用户 %s 创建分享链接" msgstr "用户 %s 创建分享链接"
#: terminal/session_lifecycle.py:57 #: terminal/session_lifecycle.py:57
#, python-format
msgid "User %s join session" msgid "User %s join session"
msgstr "用户 %s 加入会话" msgstr "用户 %s 加入会话"
#: terminal/session_lifecycle.py:69 #: terminal/session_lifecycle.py:69
#, python-format
msgid "User %s leave session" msgid "User %s leave session"
msgstr "用户 %s 离开会话" msgstr "用户 %s 离开会话"
#: terminal/session_lifecycle.py:81 #: terminal/session_lifecycle.py:81
#, python-format
msgid "User %s join to monitor session" msgid "User %s join to monitor session"
msgstr "用户 %s 监控会话" msgstr "用户 %s 监控会话"
#: terminal/session_lifecycle.py:93 #: terminal/session_lifecycle.py:93
#, python-format
msgid "User %s exit to monitor session" msgid "User %s exit to monitor session"
msgstr "用户 %s 离开监控会话" msgstr "用户 %s 离开监控会话"
@ -7229,6 +7241,7 @@ msgid "Replay successfully converted to MP4 format"
msgstr "录像成功转换成 MP4 格式" msgstr "录像成功转换成 MP4 格式"
#: terminal/session_lifecycle.py:121 #: terminal/session_lifecycle.py:121
#, python-format
msgid "Replay failed to convert to MP4 format: %s" msgid "Replay failed to convert to MP4 format: %s"
msgstr "录像转换成 MP4 格式失败: %s" msgstr "录像转换成 MP4 格式失败: %s"
@ -7241,6 +7254,7 @@ msgid "Replay successfully uploaded"
msgstr "录像成功上传" msgstr "录像成功上传"
#: terminal/session_lifecycle.py:145 #: terminal/session_lifecycle.py:145
#, python-format
msgid "Replay failed to upload: %s" msgid "Replay failed to upload: %s"
msgstr "录像上传失败:%s" msgstr "录像上传失败:%s"
@ -8508,7 +8522,7 @@ msgstr "与"
msgid "Or" msgid "Or"
msgstr "或" msgstr "或"
#: xpack/plugins/cloud/manager.py:56 #: xpack/plugins/cloud/manager.py:57
msgid "Account unavailable" msgid "Account unavailable"
msgstr "账号无效" msgstr "账号无效"

View File

@ -1,9 +1,11 @@
import json import json
import os import os
from celery.result import AsyncResult
from django.conf import settings from django.conf import settings
from django.db import transaction from django.db import transaction
from django.db.models import Count from django.db.models import Count
from django.http import Http404
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.utils._os import safe_join from django.utils._os import safe_join
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -14,6 +16,7 @@ from rest_framework.views import APIView
from assets.models import Asset from assets.models import Asset
from common.const.http import POST from common.const.http import POST
from common.permissions import IsValidUser from common.permissions import IsValidUser
from ops.celery import app
from ops.const import Types from ops.const import Types
from ops.models import Job, JobExecution from ops.models import Job, JobExecution
from ops.serializers.job import JobSerializer, JobExecutionSerializer, FileSerializer, JobTaskStopSerializer from ops.serializers.job import JobSerializer, JobExecutionSerializer, FileSerializer, JobTaskStopSerializer
@ -194,7 +197,23 @@ class JobExecutionViewSet(OrgBulkModelViewSet):
if not serializer.is_valid(): if not serializer.is_valid():
return Response({'error': serializer.errors}, status=400) return Response({'error': serializer.errors}, status=400)
task_id = serializer.validated_data['task_id'] task_id = serializer.validated_data['task_id']
instance = get_object_or_404(JobExecution, task_id=task_id, creator=request.user) try:
instance = get_object_or_404(JobExecution, task_id=task_id, creator=request.user)
except Http404:
return Response(
{'error': _('The task is being created and cannot be interrupted. Please try again later.')},
status=400
)
task = AsyncResult(task_id, app=app)
inspect = app.control.inspect()
for worker in inspect.registered().keys():
if task_id not in [at['id'] for at in inspect.active().get(worker, [])]:
# 在队列中未执行使用revoke执行
task.revoke(terminate=True)
instance.set_error('Job stop by "revoke task {}"'.format(task_id))
return Response({'task_id': task_id}, status=200)
instance.stop() instance.stop()
return Response({'task_id': task_id}, status=200) return Response({'task_id': task_id}, status=200)