Skip to content

Commit

Permalink
style: fix jinadruntime styling (#1599)
Browse files Browse the repository at this point in the history
* style: reformat jinadRuntime

* style: reformat jinadRuntime

* style: reformat jinadRuntime
  • Loading branch information
hanxiao committed Jan 5, 2021
1 parent 96e28fe commit 043a2bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test-jinad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
- name: Build jina test-pip for hubpod
run: |
docker build --build-arg PIP_TAG="[devel]" -f Dockerfiles/pip.Dockerfile -t jinaai/jina:test-pip .
- name: Build hub pod image
run: |
docker build -f tests/integration/jinad/hub_mwu/Dockerfile tests/integration/jinad/hub_mwu -t hubpod:test
sudo apt-get install jq
- name: Test jinad
run: |
./tests/integration/jinad/exec_tests.sh
Expand Down
34 changes: 21 additions & 13 deletions jina/peapods/runtimes/jinad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import argparse
import asyncio
from typing import Union, Dict, Optional
from typing import Optional

from ...zmq import Zmqlet
from .api import get_jinad_api
from ..asyncio.base import AsyncZMQRuntime
from ....helper import cached_property, ArgNamespace, colored
from ...zmq import Zmqlet
from ....helper import cached_property, colored


class JinadRuntime(AsyncZMQRuntime):

def __init__(self, args: Union['argparse.Namespace', Dict]):
def __init__(self, args: 'argparse.Namespace'):
super().__init__(args)
self.ctrl_addr = Zmqlet.get_ctrl_address(None, None, True)[0]
self.timeout_ctrl = args.timeout_ctrl
Expand All @@ -23,25 +23,33 @@ def __init__(self, args: Union['argparse.Namespace', Dict]):
logger=self.logger)

def setup(self):
# Uploads Pod/Pea context to remote & Creates remote Pod/Pea using :class:`JinadAPI`
"""
Uploads Pod/Pea context to remote & Creates remote Pod/Pea using :class:`JinadAPI`
"""
if self._remote_id:
self.logger.success(f'created remote {self.api.kind} with id {colored(self._remote_id, "cyan")}')

async def async_run_forever(self):
# Streams log messages using websocket from remote server.
self.logging_task = asyncio.create_task(self.api.logstream(self._remote_id))
"""
Streams log messages using websocket from remote server
"""
self._logging_task = asyncio.create_task(self.api.logstream(self._remote_id))

async def async_cancel(self):
# Cancels the logging task
self.logging_task.cancel()
"""
Cancels the logging task
"""
self._logging_task.cancel()

def teardown(self):
# Closes the remote Pod/Pea using :class:`JinadAPI`
"""
Closes the remote Pod/Pea using :class:`JinadAPI`
"""
self.api.delete(remote_id=self._remote_id)

@cached_property
def _remote_id(self) -> Optional[str]:
if self.api.is_alive:
args = ArgNamespace.flatten_to_dict(self.args)
if self.api.upload(args):
return self.api.create(args)
_args_dict = vars(self.args)
if self.api.upload(_args_dict):
return self.api.create(_args_dict)
9 changes: 4 additions & 5 deletions jina/peapods/runtimes/jinad/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import json
import asyncio
from pathlib import Path
import json
from contextlib import ExitStack
from multiprocessing import Event
from pathlib import Path
from typing import Dict, Tuple, Set, List, Optional

from ....jaml import JAML
from ....logging import JinaLogger
from ....enums import RemotePeapodType
from ....importer import ImportExtensions
from ....jaml import JAML
from ....logging import JinaLogger


def _add_file_to_list(_file: str, _file_list: Set, logger: 'JinaLogger'):
Expand Down

0 comments on commit 043a2bf

Please sign in to comment.