8000 fix(flow): terminate flow gracefully on error pod by hanxiao · Pull Request #1799 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(flow): terminate flow gracefully on error pod #1799

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

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions jina/flow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .. import __default_host__
from ..clients import Client, WebSocketClient
from ..enums import FlowBuildLevel, PodRoleType, FlowInspectType
from ..excepts import FlowTopologyError, FlowMissingPodError
from ..excepts import FlowTopologyError, FlowMissingPodError, RuntimeFailToStart
from ..helper import colored, \
get_public_ip, get_internal_ip, typename, ArgNamespace
from ..jaml import JAML, JAMLCompatible
Expand Down Expand Up @@ -431,11 +431,13 @@ def start(self):
for k, v in self._env.items():
os.environ[k] = str(v)

for v in self._pod_nodes.values():
self.enter_context(v)
if not v.is_ready:
self.logger.error(f'Pod {v!r} can not be started, Flow is aborted')
break
for k, v in self:
try:
self.enter_context(v)
except Exception as ex:
self.logger.error(f'{k}:{v!r} can not be started due to {ex!r}, Flow is aborted')
self.close()
raise

self.logger.info(f'{self.num_pods} Pods (i.e. {self.num_peas} Peas) are running in this Flow')

Expand Down
28 changes: 27 additions & 1 deletion tests/unit/flow/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pytest

from jina import Flow
from jina.enums import SocketType
from jina.enums import SocketType, FlowBuildLevel
from jina.excepts import RuntimeFailToStart
from jina.executors import BaseExecutor
from jina.helper import random_identity
from jina.proto.jina_pb2 import DocumentProto
Expand Down Expand Up @@ -598,3 +599,28 @@ def test_flow_identity_override():
for _, p in f:
if p.args.identity != '1234':
assert p.name == 'gateway'


def test_bad_pod_graceful_termination():
def asset_bad_flow(f):
with pytest.raises(RuntimeFailToStart):
with f:
assert f._build_level == FlowBuildLevel.EMPTY

# bad remote pod
asset_bad_flow(Flow().add(host='hello-there'))

# bad local pod
asset_bad_flow(Flow().add(uses='hello-there'))

# bad local pod at second
asset_bad_flow(Flow().add().add(uses='hello-there'))

# bad remote pod at second
asset_bad_flow(Flow().add().add(host='hello-there'))

# bad local pod at second, with correct pod at last
asset_bad_flow(Flow().add().add(uses='hello-there').add())

# bad remote pod at second, with correct pod at last
asset_bad_flow(Flow().add().add(host='hello-there').add())
0