Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第三方插件轮询支持阶梯时间间隔 #7185

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pipeline_plugins/components/collections/remote_plugin/v1_0_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 [
Expand Down Expand Up @@ -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
Expand Down
Loading