-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-processing-broker'
- Loading branch information
Showing
46 changed files
with
2,799 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
OCR-D CLI: start the processing server | ||
.. click:: ocrd.cli.processing_server:processing_server_cli | ||
:prog: ocrd processing-server | ||
:nested: full | ||
""" | ||
import click | ||
import logging | ||
from ocrd_utils import initLogging | ||
from ocrd_network import ( | ||
ProcessingServer, | ||
ProcessingServerParamType | ||
) | ||
|
||
|
||
@click.command('processing-server') | ||
@click.argument('path_to_config', required=True, type=click.STRING) | ||
@click.option('-a', '--address', | ||
default="localhost:8080", | ||
help='The URL of the Processing server, format: host:port', | ||
type=ProcessingServerParamType(), | ||
required=True) | ||
def processing_server_cli(path_to_config, address: str): | ||
""" | ||
Start and manage processing workers with the processing server | ||
PATH_TO_CONFIG is a yaml file to configure the server and the workers. See | ||
https://github.com/OCR-D/spec/pull/222/files#diff-a71bf71cbc7d9ce94fded977f7544aba4df9e7bdb8fc0cf1014e14eb67a9b273 | ||
for further information (TODO: update path when spec is available/merged) | ||
""" | ||
initLogging() | ||
# TODO: Remove before the release | ||
logging.getLogger('paramiko.transport').setLevel(logging.INFO) | ||
logging.getLogger('ocrd.network').setLevel(logging.DEBUG) | ||
|
||
# Note, the address is already validated with the type field | ||
host, port = address.split(':') | ||
processing_server = ProcessingServer(path_to_config, host, port) | ||
processing_server.start() |
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,61 @@ | ||
""" | ||
OCR-D CLI: start the processing worker | ||
.. click:: ocrd.cli.processing_worker:processing_worker_cli | ||
:prog: ocrd processing-worker | ||
:nested: full | ||
""" | ||
import click | ||
import logging | ||
from ocrd_utils import ( | ||
initLogging, | ||
get_ocrd_tool_json | ||
) | ||
from ocrd_network import ( | ||
DatabaseParamType, | ||
ProcessingWorker, | ||
QueueServerParamType, | ||
) | ||
|
||
|
||
@click.command('processing-worker') | ||
@click.argument('processor_name', required=True, type=click.STRING) | ||
@click.option('-q', '--queue', | ||
default="amqp://admin:admin@localhost:5672/", | ||
help='The URL of the Queue Server, format: amqp://username:password@host:port/vhost', | ||
type=QueueServerParamType()) | ||
@click.option('-d', '--database', | ||
default="mongodb://localhost:27018", | ||
help='The URL of the MongoDB, format: mongodb://host:port', | ||
type=DatabaseParamType()) | ||
def processing_worker_cli(processor_name: str, queue: str, database: str): | ||
""" | ||
Start a processing worker (a specific ocr-d processor) | ||
""" | ||
initLogging() | ||
# TODO: Remove before the release | ||
logging.getLogger('ocrd.network').setLevel(logging.DEBUG) | ||
|
||
# Get the ocrd_tool dictionary | ||
# ocrd_tool = parse_json_string_with_comments( | ||
# run([processor_name, '--dump-json'], stdout=PIPE, check=True, universal_newlines=True).stdout | ||
# ) | ||
|
||
ocrd_tool = get_ocrd_tool_json(processor_name) | ||
if not ocrd_tool: | ||
raise Exception(f"The ocrd_tool is empty or missing") | ||
|
||
try: | ||
processing_worker = ProcessingWorker( | ||
rabbitmq_addr=queue, | ||
mongodb_addr=database, | ||
processor_name=ocrd_tool['executable'], | ||
ocrd_tool=ocrd_tool, | ||
processor_class=None, # For readability purposes assigned here | ||
) | ||
# The RMQConsumer is initialized and a connection to the RabbitMQ is performed | ||
processing_worker.connect_consumer() | ||
# Start consuming from the queue with name `processor_name` | ||
processing_worker.start_consuming() | ||
except Exception as e: | ||
raise Exception("Processing worker has failed with error") from e |
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
Oops, something went wrong.