-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36fc83b
commit 9c8c5d9
Showing
19 changed files
with
459 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,8 @@ celerybeat-schedule | |
env/ | ||
venv/ | ||
ENV/ | ||
!env/ | ||
|
||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
spec_version: 2 | ||
app_version: "{{APP_VERSION}}" | ||
app: | ||
region: default | ||
bk_app_code: "bk_gsekit" | ||
bk_app_name: 进程配置管理 | ||
market: | ||
category: 运维工具 | ||
introduction: 进程配置管理 | ||
display_options: | ||
width: 1300 | ||
height: 720 | ||
is_win_maximize: True | ||
open_mode: "new_tab" | ||
modules: | ||
default: | ||
is_default: True | ||
source_dir: src | ||
language: Python | ||
services: | ||
- name: mysql | ||
- name: redis | ||
- name: rabbitmq | ||
env_variables: | ||
- key: BKAPP_IS_V3_CONTAINER | ||
value: "True" | ||
description: 是否部署在V3PaaS容器 | ||
- key: PIP_VERSION | ||
value: "20.2.3" | ||
description: 固化pip版本 | ||
|
||
svc_discovery: | ||
bk_saas: | ||
- bk_app_code: "bk_iam" | ||
- bk_app_code: "bk_gsekit" | ||
|
||
processes: | ||
web: | ||
command: gunicorn --timeout 600 --max-requests 200 --max-requests-jitter 20 wsgi -w 8 -b :$PORT --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"' | ||
plan: 4C2G5R | ||
replicas: 5 | ||
dworker: | ||
command: celery -A blueapps.core.celery worker -Q default -n default@%h -c 5 -l info --maxtasksperchild=50 | ||
plan: 4C2G5R | ||
replicas: 5 | ||
cworker: | ||
command: celery -A blueapps.core.celery worker -Q pipeline_additional_task,pipeline_additional_task_priority -n common_worker@%h -c 5 -l info --maxtasksperchild=50 | ||
plan: 4C2G5R | ||
replicas: 5 | ||
ereworker: | ||
command: celery -A blueapps.core.celery worker -Q er_execute -n ri_worker@%h -l info -c 10 -l info --maxtasksperchild=100 | ||
plan: 4C2G5R | ||
replicas: 5 | ||
ersworker: | ||
command: celery -A blueapps.core.celery worker -Q er_schedule -n ri_worker@%h -l info -c 10 -l info --maxtasksperchild=200 | ||
plan: 4C2G5R | ||
replicas: 5 | ||
beat: | ||
command: celery -A blueapps.core.celery beat -l info | ||
plan: 4C2G5R | ||
replicas: 1 | ||
pwatch: | ||
command: python manage.py watch_process | ||
plan: 4C2G5R | ||
replicas: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸 (Blueking) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and limitations under the License. | ||
""" | ||
import abc | ||
from enum import Enum | ||
from typing import Any, Dict, List, Tuple | ||
|
||
from ..utils.cache import class_member_cache | ||
|
||
|
||
class EnhanceEnum(Enum): | ||
"""增强枚举类,提供常用的枚举值列举方法""" | ||
|
||
@classmethod | ||
@abc.abstractmethod | ||
def _get_member__alias_map(cls) -> Dict[Enum, str]: | ||
""" | ||
获取枚举成员与释义的映射关系 | ||
:return: | ||
""" | ||
raise NotImplementedError | ||
|
||
@classmethod | ||
@class_member_cache() | ||
def list_member_values(cls) -> List[Any]: | ||
""" | ||
获取所有的枚举成员值 | ||
:return: | ||
""" | ||
member_values = [] | ||
for member in cls._member_names_: | ||
member_values.append(cls._value2member_map_[member].value) | ||
return member_values | ||
|
||
@classmethod | ||
@class_member_cache() | ||
def get_member_value__alias_map(cls) -> Dict[Any, str]: | ||
""" | ||
获取枚举成员值与释义的映射关系,缓存计算结果 | ||
:return: | ||
""" | ||
member_value__alias_map = {} | ||
member__alias_map = cls._get_member__alias_map() | ||
|
||
for member, alias in member__alias_map.items(): | ||
if type(member) is not cls: | ||
raise ValueError(f"except member type -> {cls}, but got -> {type(member)}") | ||
member_value__alias_map[member.value] = alias | ||
|
||
return member_value__alias_map | ||
|
||
@classmethod | ||
@class_member_cache() | ||
def list_choices(cls) -> List[Tuple[Any, Any]]: | ||
""" | ||
获取可选项列表,一般用于序列化器、model的choices选项 | ||
:return: | ||
""" | ||
return list(cls.get_member_value__alias_map().items()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸 (Blueking) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and limitations under the License. | ||
""" | ||
|
||
import os | ||
from typing import Any | ||
|
||
from apps.utils.string import str2bool | ||
|
||
|
||
def get_type_env(key: str, default: Any = None, _type: type = str, exempt_empty_str: bool = False) -> Any: | ||
""" | ||
获取环境变量并转为目标类型 | ||
:param key: 变量名 | ||
:param default: 默认值,若获取不到环境变量会默认使用该值 | ||
:param _type: 环境变量需要转换的类型,不会转 default | ||
:param exempt_empty_str: 是否豁免空串 | ||
:return: | ||
""" | ||
value = os.getenv(key) or default | ||
if value == default: | ||
return value | ||
|
||
# 豁免空串 | ||
if isinstance(value, str) and not value and exempt_empty_str: | ||
return value | ||
|
||
if _type == bool: | ||
return str2bool(value) | ||
|
||
try: | ||
value = _type(value) | ||
except TypeError: | ||
raise TypeError(f"can not convert env value -> {value} to type -> {_type}") | ||
|
||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸 (Blueking) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and limitations under the License. | ||
""" | ||
|
||
from typing import Optional | ||
|
||
|
||
def str2bool(string: Optional[str], strict: bool = True) -> bool: | ||
""" | ||
字符串转布尔值 | ||
对于bool(str) 仅在len(str) == 0 or str is None 的情况下为False,为了适配bool("False") 等环境变量取值情况,定义该函数 | ||
参考:https://stackoverflow.com/questions/21732123/convert-true-false-value-read-from-file-to-boolean | ||
:param string: | ||
:param strict: 严格校验,非 False / True / false / true 时抛出异常,用于环境变量的转换 | ||
:return: | ||
""" | ||
if string in ["False", "false"]: | ||
return False | ||
if string in ["True", "true"]: | ||
return True | ||
|
||
if strict: | ||
raise ValueError(f"{string} can not convert to bool") | ||
return bool(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.