Skip to content

Commit

Permalink
chore: improve http executor configs (#7730)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 authored Aug 28, 2024
1 parent 3a67fc6 commit 1262277
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
10 changes: 3 additions & 7 deletions api/core/workflow/nodes/http_request/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
from configs import dify_config
from core.workflow.entities.base_node_data_entities import BaseNodeData

MAX_CONNECT_TIMEOUT = dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT
MAX_READ_TIMEOUT = dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT
MAX_WRITE_TIMEOUT = dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT


class HttpRequestNodeAuthorizationConfig(BaseModel):
type: Literal[None, 'basic', 'bearer', 'custom']
Expand Down Expand Up @@ -41,9 +37,9 @@ class HttpRequestNodeBody(BaseModel):


class HttpRequestNodeTimeout(BaseModel):
connect: int = MAX_CONNECT_TIMEOUT
read: int = MAX_READ_TIMEOUT
write: int = MAX_WRITE_TIMEOUT
connect: int = dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT
read: int = dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT
write: int = dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT


class HttpRequestNodeData(BaseNodeData):
Expand Down
31 changes: 15 additions & 16 deletions api/core/workflow/nodes/http_request/http_request_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os import path
from typing import cast

from configs import dify_config
from core.app.segments import parser
from core.file.file_obj import FileTransferMethod, FileType, FileVar
from core.tools.tool_file_manager import ToolFileManager
Expand All @@ -11,19 +12,16 @@
from core.workflow.entities.variable_pool import VariablePool
from core.workflow.nodes.base_node import BaseNode
from core.workflow.nodes.http_request.entities import (
MAX_CONNECT_TIMEOUT,
MAX_READ_TIMEOUT,
MAX_WRITE_TIMEOUT,
HttpRequestNodeData,
HttpRequestNodeTimeout,
)
from core.workflow.nodes.http_request.http_executor import HttpExecutor, HttpExecutorResponse
from models.workflow import WorkflowNodeExecutionStatus

HTTP_REQUEST_DEFAULT_TIMEOUT = HttpRequestNodeTimeout(
connect=min(10, MAX_CONNECT_TIMEOUT),
read=min(60, MAX_READ_TIMEOUT),
write=min(20, MAX_WRITE_TIMEOUT),
connect=min(10, dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT),
read=min(60, dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT),
write=min(20, dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT),
)


Expand All @@ -43,9 +41,9 @@ def get_default_config(cls, filters: dict | None = None) -> dict:
'body': {'type': 'none'},
'timeout': {
**HTTP_REQUEST_DEFAULT_TIMEOUT.model_dump(),
'max_connect_timeout': MAX_CONNECT_TIMEOUT,
'max_read_timeout': MAX_READ_TIMEOUT,
'max_write_timeout': MAX_WRITE_TIMEOUT,
'max_connect_timeout': dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT,
'max_read_timeout': dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT,
'max_write_timeout': dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT,
},
},
}
Expand Down Expand Up @@ -92,17 +90,18 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:
},
)

def _get_request_timeout(self, node_data: HttpRequestNodeData) -> HttpRequestNodeTimeout:
@staticmethod
def _get_request_timeout(node_data: HttpRequestNodeData) -> HttpRequestNodeTimeout:
timeout = node_data.timeout
if timeout is None:
return HTTP_REQUEST_DEFAULT_TIMEOUT

timeout.connect = timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect
timeout.connect = min(timeout.connect, MAX_CONNECT_TIMEOUT)
timeout.read = timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read
timeout.read = min(timeout.read, MAX_READ_TIMEOUT)
timeout.write = timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write
timeout.write = min(timeout.write, MAX_WRITE_TIMEOUT)
timeout.connect = min(timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect,
dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT)
timeout.read = min(timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read,
dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT)
timeout.write = min(timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write,
dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT)
return timeout

@classmethod
Expand Down

0 comments on commit 1262277

Please sign in to comment.