Kumi
e82ccb2701
- Extended copyright to reflect the current year. - Incremented project version to indicate new features and fixes. - Added a new script entry for easier execution, increasing utility and accessibility. - Updated project URLs for better alignment with current infrastructure. - Refactored settings path for simplicity and consistency across deployments. - Improved code readability and maintenance across several modules by cleaning up redundant code, adding missing type annotations, and ensuring consistent code formatting. - Enhanced logging capabilities and error handling to improve diagnostics and troubleshooting, supporting more robust error recovery mechanisms. - Implemented more graceful handling of termination signals to ensure clean shutdown and resource cleanup, enhancing the robustness of the application in production environments. - Introduced command-line argument parsing for configuration file path customization, improving flexibility in different runtime environments. These changes collectively improve the project's maintainability, reliability, and user experience, laying a stronger foundation for future development.
71 lines
1.8 KiB
Python
Executable file
71 lines
1.8 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
from contentmonster.classes.config import MonsterConfig
|
|
from contentmonster.classes.vesselthread import VesselThread
|
|
from contentmonster.classes.shorethread import ShoreThread
|
|
|
|
from multiprocessing import Manager
|
|
from argparse import ArgumentParser
|
|
|
|
import pathlib
|
|
import time
|
|
import logging
|
|
import signal
|
|
|
|
# Setup basic logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
def setup_signal_handlers(shore, threads):
|
|
def signal_handler(signum, frame):
|
|
logging.info("Signal received - stopping threads")
|
|
shore.terminate()
|
|
for thread in threads:
|
|
thread.terminate()
|
|
exit(0)
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
|
|
|
def main():
|
|
parser = ArgumentParser(description="ContentMonster Worker")
|
|
parser.add_argument("-c", "--config", help="Path to configuration file")
|
|
args = parser.parse_args()
|
|
|
|
if args.config:
|
|
config_path = args.config
|
|
else:
|
|
config_path = "settings.ini"
|
|
|
|
config = MonsterConfig()
|
|
|
|
try:
|
|
config.readFile(config_path)
|
|
except Exception as e:
|
|
logging.error(f"Failed to read configuration: {e}")
|
|
return
|
|
|
|
with Manager() as manager:
|
|
state = manager.dict()
|
|
state["files"] = manager.list()
|
|
state["config"] = config
|
|
|
|
threads = []
|
|
|
|
for vessel in config.vessels:
|
|
thread = VesselThread(vessel, state)
|
|
thread.start()
|
|
threads.append(thread)
|
|
|
|
shore = ShoreThread(state)
|
|
shore.start()
|
|
|
|
setup_signal_handlers(shore, threads)
|
|
|
|
while True:
|
|
try:
|
|
time.sleep(10)
|
|
except Exception as e:
|
|
logging.error(f"Unexpected error: {e}")
|
|
break
|
|
|
|
if __name__ == '__main__':
|
|
main() |