-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
490f486
commit 75c5d40
Showing
15 changed files
with
317 additions
and
79 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
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,63 @@ | ||
# Copyright (c) Regents of the University of Minnesota. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from argparse import ArgumentParser | ||
from typing import List | ||
|
||
from mtap.pipeline import pipeline_parser, run_pipeline_server | ||
|
||
from biomedicus_client import default_pipeline | ||
from biomedicus_client.cli_tools import Command | ||
|
||
|
||
class ServePipeline(Command): | ||
@property | ||
def command(self) -> str: | ||
return "serve-pipeline" | ||
|
||
@property | ||
def help(self) -> str: | ||
return "Starts the end-to-end BioMedICUS pipeline service." | ||
|
||
@property | ||
def parents(self) -> List[ArgumentParser]: | ||
return [pipeline_parser()] | ||
|
||
def add_arguments(self, parser: ArgumentParser): | ||
parser.add_argument( | ||
'--config', | ||
default=None, | ||
help='Path to the pipeline configuration file.' | ||
) | ||
parser.add_argument( | ||
'--include-label-text', | ||
action='store_true', | ||
help="Flag to include the covered text for every label" | ||
) | ||
parser.add_argument( | ||
'--rtf', | ||
action='store_true', | ||
help="Flag to use a source for the rtf reader instead of plain text." | ||
) | ||
parser.add_argument( | ||
'--rtf-address', | ||
help="The address (or addresses, comma separated) for the rtf to text converter processor." | ||
) | ||
|
||
def command_fn(self, conf): | ||
if conf.port == 0: | ||
conf.port = 55000 | ||
conf.serializer = None | ||
pipeline = default_pipeline.from_args(conf) | ||
run_pipeline_server(pipeline, conf) |
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,64 @@ | ||
# Copyright (c) Regents of the University of Minnesota. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
import threading | ||
import traceback | ||
from contextlib import suppress | ||
from subprocess import Popen, PIPE, STDOUT | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(name='deploy_all', scope='module') | ||
def fixture_deploy_all(processor_timeout): | ||
p = None | ||
listener = None | ||
try: | ||
p = Popen([sys.executable, '-m', 'biomedicus', 'deploy', '--rtf', | ||
'--noninteractive', '--log-level', 'DEBUG', | ||
'--startup-timeout', str(processor_timeout)], | ||
stdout=PIPE, stderr=STDOUT) | ||
e = threading.Event() | ||
|
||
def listen(): | ||
print("Starting listener", flush=True) | ||
for line in p.stdout: | ||
line = line.decode() | ||
print(line, end='', flush=True) | ||
if line.startswith("Done deploying all servers."): | ||
e.set() | ||
p.wait() | ||
e.set() | ||
|
||
listener = threading.Thread(target=listen) | ||
listener.start() | ||
e.wait(timeout=processor_timeout) | ||
if p.returncode is not None: | ||
raise ValueError("Failed to deploy.") | ||
print("Done starting deployment for tests, yielding to test functions.", flush=True) | ||
yield p | ||
finally: | ||
try: | ||
if p is not None: | ||
p.terminate() | ||
if listener is not None: | ||
with suppress(TimeoutError): | ||
listener.join(timeout=60.0) | ||
if listener.is_alive(): | ||
p.kill() | ||
listener.join(timeout=10.0) | ||
except Exception: | ||
print("Error cleaning up deployment") | ||
traceback.print_exc() |
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
Oops, something went wrong.