Skip to content

Commit

Permalink
feat(server): add GRPC_WORKER_MODE config to change worker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fenngwd committed Jun 24, 2022
1 parent 49b46fa commit 6077922
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions sea/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BaseApp:
"TIMEZONE": "UTC",
"GRPC_WORKERS": 4,
"GRPC_THREADS": 1, # Only appliable in multiprocessing server
"GRPC_WORKER_MODE": "threading", # Worker mode. threading|multiprocessing
"GRPC_HOST": "0.0.0.0",
"GRPC_PORT": 6000,
"GRPC_LOG_LEVEL": "WARNING",
Expand Down
20 changes: 17 additions & 3 deletions sea/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@

from sea import current_app
from sea.cli import JobException, jobm
from sea.server import Server


@jobm.job("server", aliases=["s"], help="Run Server")
def server():
s = Server(current_app)
@jobm.option(
"-M",
"--worker_mode",
required=False,
action="store",
help="Worker mode. threading|multiprocessing",
)
def server(worker_mode):
worker_mode = worker_mode or current_app.config["GRPC_WORKER_MODE"]
if worker_mode == "threading":
from sea.server.threading import Server

s = Server(current_app)
else:
from sea.server.multiprocessing import Server

s = Server(current_app)
s.run()
return 0

Expand Down
12 changes: 9 additions & 3 deletions tests/test_cmds.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import sys
import pytest
import os
import shutil
import sys
from unittest import mock

import pytest

from sea import cli


def test_cmd_server(app):
sys.argv = "sea s".split()
with mock.patch("sea.cmds.Server", autospec=True) as mocked:
with mock.patch("sea.server.threading.Server", autospec=True) as mocked:
assert cli.main() == 0
mocked.return_value.run.assert_called_with()

sys.argv = "sea s -M multiprocessing".split()
with mock.patch("sea.server.multiprocessing.Server", autospec=True) as mocked:
assert cli.main() == 0
mocked.return_value.run.assert_called_with()

Expand Down

0 comments on commit 6077922

Please sign in to comment.