Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(flow): allow add service to be str
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Oct 14, 2019
1 parent 7d2c681 commit b94490f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gnes/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def add_router(self, *args, **kwargs) -> 'Flow':
"""Add a router to the current flow, a shortcut of :py:meth:`add(Service.Router)`"""
return self.add(Service.Router, *args, **kwargs)

def add(self, service: 'Service',
def add(self, service: Union['Service', str],
name: str = None,
service_in: Union[str, Tuple[str], List[str], 'Service'] = None,
service_out: Union[str, Tuple[str], List[str], 'Service'] = None,
Expand All @@ -329,7 +329,7 @@ def add(self, service: 'Service',
"""
Add a service to the current flow object and return the new modified flow object
:param service: a 'Service' enum, possible choices: Encoder, Router, Preprocessor, Indexer, Frontend
:param service: a 'Service' enum or string, possible choices: Encoder, Router, Preprocessor, Indexer, Frontend
:param name: the name indentifier of the service, useful in 'service_in' and 'service_out'
:param service_in: the name of the service(s) that this service receives data from.
One can also use 'Service.Frontend' to indicate the connection with the frontend.
Expand All @@ -342,6 +342,9 @@ def add(self, service: 'Service',

op_flow = copy.deepcopy(self) if copy_flow else self

if isinstance(service, str):
service = Service.from_string(service)

if service not in Flow._service2parser:
raise ValueError('service: %s is not supported, should be one of %s' % (service, Flow._service2parser))

Expand Down
2 changes: 1 addition & 1 deletion gnes/service/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def from_string(cls, s):
try:
return cls[s]
except KeyError:
raise ValueError()
raise ValueError('%s is not a valid enum for %s' % (s, cls))


class ReduceOp(BetterEnum):
Expand Down

0 comments on commit b94490f

Please sign in to comment.