Skip to content

Commit

Permalink
fix broken logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Oct 14, 2024
1 parent 85bde15 commit 41c0ce8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
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()
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

0 comments on commit 41c0ce8

Please sign in to comment.