From e71e335f5c84c0ff12fc6bbd601a9cda612b7faa Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Mon, 26 Feb 2024 18:04:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=88=E6=96=AD=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E6=8E=A5=E5=8F=A3=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/locale/ja/LC_MESSAGES/django.mo | 4 ++-- apps/locale/ja/LC_MESSAGES/django.po | 24 +++++++++++++++++++----- apps/locale/zh/LC_MESSAGES/django.mo | 4 ++-- apps/locale/zh/LC_MESSAGES/django.po | 22 ++++++++++++++++++---- apps/ops/api/job.py | 21 ++++++++++++++++++++- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/apps/locale/ja/LC_MESSAGES/django.mo b/apps/locale/ja/LC_MESSAGES/django.mo index 45714f01c..b9f102de9 100644 --- a/apps/locale/ja/LC_MESSAGES/django.mo +++ b/apps/locale/ja/LC_MESSAGES/django.mo @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c9446906e12d6db2687753ded172353a7df3b087db0d0d848bf10158d611fc1b -size 171615 +oid sha256:d04781f4f0b0de3ac5f707febb222e239553d6103bca0cec41ab2fd5ab044571 +size 173799 diff --git a/apps/locale/ja/LC_MESSAGES/django.po b/apps/locale/ja/LC_MESSAGES/django.po index aae98f99a..12f6425f0 100644 --- a/apps/locale/ja/LC_MESSAGES/django.po +++ b/apps/locale/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4077,11 +4077,11 @@ msgstr "タスクは存在しません" msgid "Task {} args or kwargs error" msgstr "タスク実行パラメータエラー" -#: ops/api/job.py:132 +#: ops/api/job.py:135 msgid "Duplicate file exists" msgstr "重複したファイルが存在する" -#: ops/api/job.py:137 +#: ops/api/job.py:140 #, python-brace-format msgid "" "File size exceeds maximum limit. Please select a file smaller than {limit}MB" @@ -4089,6 +4089,11 @@ 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 msgid "Currently playbook is being used in a job" msgstr "現在プレイブックは1つのジョブで使用されています" @@ -7294,30 +7299,37 @@ msgid "Container Ports" msgstr "コンテナポート" #: terminal/session_lifecycle.py:30 +#, python-format msgid "Connect to asset %s success" msgstr "アセット %s への接続に成功しました" #: terminal/session_lifecycle.py:38 +#, python-format msgid "Connect to asset %s finished: %s" msgstr "アセット %s への接続が完了しました: %s" #: terminal/session_lifecycle.py:48 +#, python-format msgid "User %s create share link" msgstr "ユーザー %s が共有リンクを作成しました" #: terminal/session_lifecycle.py:57 +#, python-format msgid "User %s join session" msgstr "ユーザー %s がセッションに参加しました" #: terminal/session_lifecycle.py:69 +#, python-format msgid "User %s leave session" msgstr "ユーザー %s がセッションを離れました" #: terminal/session_lifecycle.py:81 +#, python-format msgid "User %s join to monitor session" msgstr "ユーザー %s がモニターセッションに参加しました" #: terminal/session_lifecycle.py:93 +#, python-format msgid "User %s exit to monitor session" msgstr "ユーザー %s がモニターセッションを離れました" @@ -7330,6 +7342,7 @@ msgid "Replay successfully converted to MP4 format" msgstr "リプレイが正常にMP4形式に変換されました" #: terminal/session_lifecycle.py:121 +#, python-format msgid "Replay failed to convert to MP4 format: %s" msgstr "リプレイのMP4形式への変換に失敗しました: %s" @@ -7342,10 +7355,11 @@ msgid "Replay successfully uploaded" msgstr "リプレイが正常にアップロードされました" #: terminal/session_lifecycle.py:145 +#, python-format msgid "Replay failed to upload: %s" msgstr "リプレイのアップロードに失敗しました: %s" -#: terminal/session_lifecycle.py:152" +#: terminal/session_lifecycle.py:152 msgid "connect failed" msgstr "接続に失敗しました" @@ -8632,7 +8646,7 @@ msgstr "そして" msgid "Or" msgstr "または" -#: xpack/plugins/cloud/manager.py:56 +#: xpack/plugins/cloud/manager.py:57 msgid "Account unavailable" msgstr "利用できないアカウント" diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index ffb6db050..3905e0b73 100644 --- a/apps/locale/zh/LC_MESSAGES/django.mo +++ b/apps/locale/zh/LC_MESSAGES/django.mo @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:78af89ae300362f26852652ebd1abcf24885a2c2ab1154baba2a4a20f16e2817 -size 140688 +oid sha256:e66a6fa05d25f1c502f95001b5ff0d0a310affd32eac939fd7b840845028074f +size 142298 diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 29c889f18..9bf7548c0 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\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" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -4028,16 +4028,21 @@ msgstr "任务 {} 不存在" msgid "Task {} args or kwargs error" msgstr "任务 {} 执行参数错误" -#: ops/api/job.py:132 +#: ops/api/job.py:135 msgid "Duplicate file exists" msgstr "存在同名文件" -#: ops/api/job.py:137 +#: ops/api/job.py:140 #, python-brace-format msgid "" "File size exceeds maximum limit. Please select a file smaller than {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 msgid "Currently playbook is being used in a job" msgstr "当前 playbook 正在作业中使用" @@ -7193,30 +7198,37 @@ msgid "Container Ports" msgstr "容器端口" #: terminal/session_lifecycle.py:30 +#, python-format msgid "Connect to asset %s success" msgstr "连接资产 %s 成功" #: terminal/session_lifecycle.py:38 +#, python-format msgid "Connect to asset %s finished: %s" msgstr "连接资产 %s 结束: %s" #: terminal/session_lifecycle.py:48 +#, python-format msgid "User %s create share link" msgstr "用户 %s 创建分享链接" #: terminal/session_lifecycle.py:57 +#, python-format msgid "User %s join session" msgstr "用户 %s 加入会话" #: terminal/session_lifecycle.py:69 +#, python-format msgid "User %s leave session" msgstr "用户 %s 离开会话" #: terminal/session_lifecycle.py:81 +#, python-format msgid "User %s join to monitor session" msgstr "用户 %s 监控会话" #: terminal/session_lifecycle.py:93 +#, python-format msgid "User %s exit to monitor session" msgstr "用户 %s 离开监控会话" @@ -7229,6 +7241,7 @@ msgid "Replay successfully converted to MP4 format" msgstr "录像成功转换成 MP4 格式" #: terminal/session_lifecycle.py:121 +#, python-format msgid "Replay failed to convert to MP4 format: %s" msgstr "录像转换成 MP4 格式失败: %s" @@ -7241,6 +7254,7 @@ msgid "Replay successfully uploaded" msgstr "录像成功上传" #: terminal/session_lifecycle.py:145 +#, python-format msgid "Replay failed to upload: %s" msgstr "录像上传失败:%s" @@ -8508,7 +8522,7 @@ msgstr "与" msgid "Or" msgstr "或" -#: xpack/plugins/cloud/manager.py:56 +#: xpack/plugins/cloud/manager.py:57 msgid "Account unavailable" msgstr "账号无效" diff --git a/apps/ops/api/job.py b/apps/ops/api/job.py index 4c60956fd..a2a0c00ee 100644 --- a/apps/ops/api/job.py +++ b/apps/ops/api/job.py @@ -1,9 +1,11 @@ import json import os +from celery.result import AsyncResult from django.conf import settings from django.db import transaction from django.db.models import Count +from django.http import Http404 from django.shortcuts import get_object_or_404 from django.utils._os import safe_join from django.utils.translation import gettext_lazy as _ @@ -14,6 +16,7 @@ from rest_framework.views import APIView from assets.models import Asset from common.const.http import POST from common.permissions import IsValidUser +from ops.celery import app from ops.const import Types from ops.models import Job, JobExecution from ops.serializers.job import JobSerializer, JobExecutionSerializer, FileSerializer, JobTaskStopSerializer @@ -194,7 +197,23 @@ class JobExecutionViewSet(OrgBulkModelViewSet): if not serializer.is_valid(): return Response({'error': serializer.errors}, status=400) 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() return Response({'task_id': task_id}, status=200)