From c080d5f86743e25b69d6f155f52abdc4e5ab2f62 Mon Sep 17 00:00:00 2001 From: waylon <1158341873@qq.com> Date: Thu, 23 Nov 2023 17:54:25 +0800 Subject: [PATCH] =?UTF-8?q?optimization:=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=BD=AE=E8=AF=A2=E6=94=AF=E6=8C=81=E9=98=B6?= =?UTF-8?q?=E6=A2=AF=E6=97=B6=E9=97=B4=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collections/remote_plugin/v1_0_0.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py b/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py index 7f77e431f7..aee7e5633a 100644 --- a/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py +++ b/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py @@ -12,13 +12,14 @@ """ import logging +from django.utils.translation import ugettext_lazy as _ from pipeline.component_framework.component import Component -from pipeline.core.flow import Service, StaticIntervalGenerator +from pipeline.core.flow import AbstractIntervalGenerator, Service from pipeline.core.flow.io import StringItemSchema + from plugin_service.conf import PLUGIN_LOGGER from plugin_service.exceptions import PluginServiceException from plugin_service.plugin_client import PluginServiceApiClient -from django.utils.translation import ugettext_lazy as _ logger = logging.getLogger(PLUGIN_LOGGER) @@ -34,8 +35,15 @@ class State: UNFINISHED_STATES = {State.POLL, State.CALLBACK} +class StepIntervalGenerator(AbstractIntervalGenerator): + def next(self): + super(StepIntervalGenerator, self).next() + # 最小 10s,最大 3600s 一次 + return 10 if self.count < 30 else min((self.count - 25) ** 2, 3600) + + class RemotePluginService(Service): - interval = StaticIntervalGenerator(5) + interval = StepIntervalGenerator() def outputs_format(self): return [ @@ -72,9 +80,7 @@ def execute(self, data, parent_data): ) ok, result_data = plugin_client.invoke(plugin_version, {"inputs": data.inputs, "context": plugin_context}) if not ok: - message = _( - f"调用第三方插件invoke接口错误, 错误内容: {result_data['message']}, trace_id: {result_data.get('trace_id')}" - ) + message = _(f"调用第三方插件invoke接口错误, 错误内容: {result_data['message']}, trace_id: {result_data.get('trace_id')}") logger.error(message) data.set_outputs("ex_data", message) return False