-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupload_main.py
More file actions
81 lines (65 loc) · 2.87 KB
/
Copy pathupload_main.py
File metadata and controls
81 lines (65 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Entry point for DICOM upload listener service."""
import logging
import os
from dotenv import load_dotenv
from services.dicom.dicom_uploader import DICOMUploader
from services.dicom.upload_listener import UploadListener
from services.dicom.upload_processor import UploadProcessor
from services.storage import MWLStorage, PACSStorage
from telemetry import configure_telemetry
load_dotenv()
def main():
"""
Main entry point for upload listener service.
Environment variables:
CLOUD_API_ENDPOINT: URL of the cloud API endpoint to upload to (default: http://localhost:8000/api/dicom/upload)
CLOUD_API_KEY: API key for authenticating with the cloud API (default: none)
MAX_UPLOAD_RETRIES: Maximum number of upload retries before giving up (default: 3)
MWL_DB_PATH: Path to the MWL SQLite database file (default: /var/lib/pacs/worklist.db)
PACS_DB_PATH: Path to the PACS SQLite database file (default: /var/lib/pacs/pacs.db)
PACS_STORAGE_PATH: Path to the directory where DICOM files are stored (default: /var/lib/pacs/storage)
UPLOAD_POLL_INTERVAL: Time in seconds between polling for new uploads (default: 2)
UPLOAD_BATCH_SIZE: Number of pending uploads to process in each batch (default: 10)
"""
logging.basicConfig(
level=os.getenv("LOG_LEVEL", "INFO").upper(),
format=os.getenv("LOG_FORMAT", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"),
)
poll_interval = float(os.getenv("UPLOAD_POLL_INTERVAL", "2"))
batch_size = int(os.getenv("UPLOAD_BATCH_SIZE", "10"))
max_retries = int(os.getenv("MAX_UPLOAD_RETRIES", "3"))
pacs_storage = PACSStorage(
os.getenv("PACS_DB_PATH", "/var/lib/pacs/pacs.db"), os.getenv("PACS_STORAGE_PATH", "/var/lib/pacs/storage")
)
mwl_storage = MWLStorage(os.getenv("MWL_DB_PATH", "/var/lib/pacs/worklist.db"))
uploader = DICOMUploader()
processor = UploadProcessor(
pacs_storage=pacs_storage,
mwl_storage=mwl_storage,
uploader=uploader,
max_retries=max_retries,
)
listener = UploadListener(
processor=processor,
poll_interval=poll_interval,
batch_size=batch_size,
)
logging.info("=" * 60)
logging.info("Starting DICOM upload listener service")
logging.info("=" * 60)
logging.info(f"PACS DB: {pacs_storage.db_path}")
logging.info(f"Worklist DB: {mwl_storage.db_path}")
logging.info(f"Storage: {pacs_storage.storage_root}")
logging.info(f"Poll interval: {poll_interval}s")
logging.info(f"Batch size: {batch_size}")
logging.info(f"Max retries: {max_retries}")
logging.info(f"API endpoint: {uploader.api_endpoint}")
logging.info("=" * 60)
configure_telemetry(service_name="upload-listener")
try:
listener.start()
except KeyboardInterrupt:
logging.info("Received shutdown signal")
listener.stop()
if __name__ == "__main__":
main()