Skip to content

Commit

Permalink
fix: 修复任务未启动时变量存在引用时异常的问题 #ignore (#7312)
Browse files Browse the repository at this point in the history
* fix: 修复任务未启动时变量存在引用时异常的问题 #ignore

* fix: 修复任务未启动时变量存在引用时异常的问题 #ignore

* feat: release 3.31.18 #ignore
  • Loading branch information
hanshuaikang authored Jan 19, 2024
1 parent 005ce29 commit 1529d5a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ is_use_celery: True
author: 蓝鲸智云
introduction: 标准运维是通过一套成熟稳定的任务调度引擎,把在多系统间的工作整合到一个流程,助力运维实现跨系统调度自动化的SaaS应用。
introduction_en: SOPS is a SaaS application that utilizes a set of mature and stable task scheduling engines to help realize cross-system scheduling automation, and integrates the work among multiple systems into a single process.
version: 3.31.17
version: 3.31.18
category: 运维工具
language_support: 中文
desktop:
Expand Down
2 changes: 1 addition & 1 deletion app_desc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spec_version: 2
app_version: "3.31.17"
app_version: "3.31.18"
app:
region: default
bk_app_code: bk_sops
Expand Down
3 changes: 2 additions & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
# mako模板中:<script src="/a.js?v=${ STATIC_VERSION }"></script>
# 如果静态资源修改了以后,上线前改这个版本号即可

STATIC_VERSION = "3.31.17"
STATIC_VERSION = "3.31.18"
DEPLOY_DATETIME = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
Expand Down Expand Up @@ -678,6 +678,7 @@ def monitor_report_config():

from bk_monitor_report import MonitorReporter # noqa
from bk_monitor_report.contrib.celery import MonitorReportStep # noqa

from blueapps.core.celery import celery_app # noqa

reporter = MonitorReporter(
Expand Down
46 changes: 32 additions & 14 deletions gcloud/tasktmpl3/domains/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 copy
import logging
import re
from typing import List
Expand All @@ -19,6 +19,7 @@
from bamboo_engine.eri import ContextValue, NodeType
from bamboo_engine.template import Template
from bamboo_engine.utils.constants import VAR_CONTEXT_MAPPING
from pipeline.component_framework.constant import ConstantPool
from pipeline.core.data import var
from pipeline.core.data.expression import ConstantTemplate
from pipeline.core.data.library import VariableLibrary
Expand Down Expand Up @@ -74,6 +75,31 @@ def get_constant_values(constants, extra_data):
return {**constant_values, **hydrated_context}


def get_references(constants: dict, inputs: dict) -> set:
"""
获取某个变量在上下文中引用的其他变量
@param constants: {"${ip_lisr}: {}"}
@param inputs: {"${ip_lisr}": {"value": xxx}}
@return: ["${ip_lisr}"]
"""
referenced_keys = []
while True:
last_count = len(referenced_keys)
cons_pool = ConstantPool(inputs, lazy=True)
refs = cons_pool.get_reference_info(strict=False)

for keys in list(refs.values()):
for key in keys:
# add outputs keys later
if key in constants and key not in referenced_keys:
referenced_keys.append(key)
inputs.update({key: constants[key]})
if len(referenced_keys) == last_count:
break

return set(referenced_keys)


def preview_node_inputs(
runtime: BambooDjangoRuntime,
pipeline: dict,
Expand All @@ -84,21 +110,13 @@ def preview_node_inputs(
subprocess_simple_inputs: bool = False,
):
def get_need_render_context_keys():
keys = set()
# 如果遇到子流程,到最后一层才会实际去解析需要渲染的变量
node_info = pipeline["activities"][node_id]
inputs_values = node_info.get("component", {}).get("inputs", {}).values()
for item in inputs_values:
if not item["need_render"]:
continue
if isinstance(item["value"], str):
for value in var_pattern.findall(item["value"]):
keys.add("${" + value + "}")

if keys:
references_keys = runtime.get_context_key_references(pipeline["id"], keys)
return keys | references_keys
return set()
node_inputs = copy.deepcopy(node_info.get("component", {}).get("inputs", {}))
pipeline_inputs = copy.deepcopy(pipeline["data"].get("inputs", {}))
pipeline_inputs.update(parent_params)
keys = get_references(pipeline_inputs, node_inputs)
return keys

# 对于子流程内的节点,拿不到当前node_id的type和code
node_type = pipeline["activities"].get(node_id, {}).get("type")
Expand Down

0 comments on commit 1529d5a

Please sign in to comment.