Skip to content

Commit df8fd1c

Browse files
committed
fix: 修复常量定义规范问题 --story=129476203
# Reviewed, transaction id: 71505
1 parent fccccde commit df8fd1c

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

bkflow/apigw/views/operate_task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from bkflow.apigw.decorators import check_jwt_and_space, return_json_response
2828
from bkflow.apigw.serializers.task import OperateTaskSerializer
29-
from bkflow.constants import OPERATE_EVENT, WebhookScopeType
29+
from bkflow.constants import OPERATE_EVENT_MAP, WebhookScopeType
3030
from bkflow.contrib.api.collections.task import TaskComponentClient
3131
from bkflow.utils.trace import CallFrom, append_attributes, start_trace
3232

@@ -48,9 +48,9 @@ def operate_task(request, space_id, task_id, operation):
4848
client = TaskComponentClient(space_id=space_id)
4949
result = client.operate_task(task_id, operation, data=ser.data)
5050

51-
if operation in OPERATE_EVENT:
51+
if operation in ["pause", "resume", "revoke"]:
5252
event_broadcast_signal.send(
53-
sender=OPERATE_EVENT[operation],
53+
sender=OPERATE_EVENT_MAP[operation],
5454
scopes=[(WebhookScopeType.SPACE.value, str(space_id))],
5555
extra_info={"task_id": task_id, "operation": operation, "username": request.user.username},
5656
)

bkflow/constants.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
formatted_key_pattern = re.compile(r"^\${(.*?)}$")
3434

35-
OPERATE_EVENT = {"pause": "task_paused", "resume": "task_resumed", "revoke": "task_revoked"}
36-
3735

3836
class PipelineContextObjType(Enum):
3937
instance = "instance"
@@ -132,6 +130,13 @@ class WebhookEventType(Enum):
132130
TASK_REVOKED = "task_revoked"
133131

134132

133+
OPERATE_EVENT_MAP = {
134+
"pause": WebhookEventType.TASK_PAUSED.value,
135+
"resume": WebhookEventType.TASK_RESUMED.value,
136+
"revoke": WebhookEventType.TASK_REVOKED.value,
137+
}
138+
139+
135140
class TriggerConstantsMode(Enum):
136141
"""触发器参数视图类型"""
137142

bkflow/task/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from rest_framework.response import Response
3030

3131
from bkflow.constants import (
32-
OPERATE_EVENT,
32+
OPERATE_EVENT_MAP,
3333
RecordType,
3434
TaskOperationSource,
3535
TaskOperationType,
@@ -204,12 +204,12 @@ def operate(self, request, operation, *args, **kwargs):
204204
operator = data.pop("operator", request.user.username)
205205
operation_result = operation_method(operator=operator, **data)
206206

207-
if operation in OPERATE_EVENT:
207+
if operation in ["pause", "resume", "revoke"]:
208208
interface_client = InterfaceModuleClient()
209209
interface_client.broadcast_task_events(
210210
data={
211211
"space_id": task_instance.space_id,
212-
"event": OPERATE_EVENT[operation],
212+
"event": OPERATE_EVENT_MAP[operation],
213213
"extra_info": {"task_id": task_instance.id},
214214
}
215215
)

0 commit comments

Comments
 (0)