Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken ocrd_network processing worker logs #1292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ocrd_network/processing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class ProcessingServer(FastAPI):
"""

def __init__(self, config_path: str, host: str, port: int) -> None:
initLogging()
self.title = "OCR-D Processing Server"
super().__init__(
title=self.title,
on_startup=[self.on_startup],
on_shutdown=[self.on_shutdown],
description="OCR-D Processing Server"
)
initLogging()
bertsky marked this conversation as resolved.
Show resolved Hide resolved
self.log = getLogger("ocrd_network.processing_server")
log_file = get_processing_server_logging_file_path(pid=getpid())
configure_file_handler_with_formatter(self.log, log_file=log_file, mode="a")
Expand Down Expand Up @@ -156,7 +156,7 @@ def start(self) -> None:
queue_names = self.deployer.find_matching_network_agents(
worker_only=True, str_names_only=True, unique_only=True
)
self.log.debug(f"Creating message queues on RabbitMQ instance url: {self.rabbitmq_url}")
self.log.info(f"Creating message queues on RabbitMQ instance url: {self.rabbitmq_url}")
create_message_queues(logger=self.log, rmq_publisher=self.rmq_publisher, queue_names=queue_names)

self.deployer.deploy_network_agents(mongodb_url=self.mongodb_url, rabbitmq_url=self.rabbitmq_url)
Expand All @@ -168,6 +168,7 @@ def start(self) -> None:
uvicorn_run(self, host=self.hostname, port=int(self.port))

async def on_startup(self):
self.log.info(f"Initializing the Database on: {self.mongodb_url}")
await initiate_database(db_url=self.mongodb_url)

async def on_shutdown(self) -> None:
Expand Down
9 changes: 6 additions & 3 deletions src/ocrd_network/processing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"""

from datetime import datetime
from os import getpid
from os import getpid, getppid
from pika import BasicProperties
from pika.adapters.blocking_connection import BlockingChannel
from pika.spec import Basic

from ocrd_utils import getLogger
from ocrd_utils import getLogger, initLogging
from .constants import JobState
from .database import sync_initiate_database, sync_db_get_workspace, sync_db_update_processing_job, verify_database_uri
from .logging_utils import (
Expand All @@ -35,14 +35,16 @@

class ProcessingWorker:
def __init__(self, rabbitmq_addr, mongodb_addr, processor_name, ocrd_tool: dict, processor_class=None) -> None:
initLogging()
self.log = getLogger(f'ocrd_network.processing_worker')
log_file = get_processing_worker_logging_file_path(processor_name=processor_name, pid=getpid())
configure_file_handler_with_formatter(self.log, log_file=log_file, mode="a")

try:
verify_database_uri(mongodb_addr)
self.log.debug(f'Verified MongoDB URL: {mongodb_addr}')
self.log.info(f'Verified MongoDB URL: {mongodb_addr}')
self.rmq_data = verify_and_parse_mq_uri(rabbitmq_addr)
self.log.info(f'Verified RabbitMQ URL: {rabbitmq_addr}')
except ValueError as error:
msg = f"Failed to parse data, error: {error}"
self.log.exception(msg)
Expand All @@ -61,6 +63,7 @@ def __init__(self, rabbitmq_addr, mongodb_addr, processor_name, ocrd_tool: dict,
# Gets assigned when the `connect_publisher` is called on the worker object
# Used to publish OcrdResultMessage type message to the queue with name {processor_name}-result
self.rmq_publisher = None
self.log.info(f"Initialized processing worker: {processor_name}")

def connect_consumer(self):
self.rmq_consumer = connect_rabbitmq_consumer(self.log, self.rmq_data)
Expand Down
3 changes: 2 additions & 1 deletion src/ocrd_network/processor_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class ProcessorServer(FastAPI):
def __init__(self, mongodb_addr: str, processor_name: str = "", processor_class=None):
if not (processor_name or processor_class):
raise ValueError("Either 'processor_name' or 'processor_class' must be provided")
initLogging()
super().__init__(
on_startup=[self.on_startup],
on_shutdown=[self.on_shutdown],
title=f"Network agent - Processor Server",
description="Network agent - Processor Server"
)
initLogging()
self.log = getLogger("ocrd_network.processor_server")
log_file = get_processor_server_logging_file_path(processor_name=processor_name, pid=getpid())
configure_file_handler_with_formatter(self.log, log_file=log_file, mode="a")
Expand All @@ -69,6 +69,7 @@ def __init__(self, mongodb_addr: str, processor_name: str = "", processor_class=
self.processor_name = self.ocrd_tool["executable"]

self.add_api_routes_processing()
self.log.info(f"Initialized processor server: {processor_name}")

async def on_startup(self):
await initiate_database(db_url=self.db_url)
Expand Down
Loading