-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: abstract the construction of different pods (#2346)
- Loading branch information
Showing
6 changed files
with
122 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Union, Optional, Dict, Set | ||
from argparse import Namespace | ||
|
||
from .. import Pod | ||
from .. import BasePod | ||
from .compoundpod import CompoundPod | ||
|
||
|
||
class PodFactory: | ||
""" | ||
A PodFactory is a factory class, abstracting the Pod creation | ||
""" | ||
|
||
@staticmethod | ||
def build_pod( | ||
args: Union['Namespace', Dict], needs: Optional[Set[str]] = None | ||
) -> BasePod: | ||
"""Build an implementation of a `BasePod` interface | ||
:param args: pod arguments parsed from the CLI. | ||
:param needs: pod names of preceding pods | ||
:return: the created BasePod | ||
""" | ||
if args.replicas > 1: | ||
return CompoundPod(args, needs=needs) | ||
else: | ||
return Pod(args, needs=needs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from jina.peapods.pods.factory import PodFactory | ||
from jina.peapods.pods import Pod | ||
from jina.peapods.pods.compoundpod import CompoundPod | ||
from jina.parsers import set_pod_parser | ||
|
||
|
||
def test_pod_factory_pod(): | ||
args_no_replicas = set_pod_parser().parse_args(['--replicas', '1']) | ||
assert isinstance(PodFactory.build_pod(args_no_replicas), Pod) | ||
|
||
args_replicas = set_pod_parser().parse_args(['--replicas', '2']) | ||
assert isinstance(PodFactory.build_pod(args_replicas), CompoundPod) |