Update ingestor and data manager for improved shutdown handling and logging - Incremented project version in quality gate configuration. - Commented out ingestor service in docker-compose for clarity. - Enhanced main loop in app.py to handle exit signals and exceptions. - Added shutdown methods in Ingestor and DataManager classes for graceful resource cleanup. - Updated unit tests to validate shutdown behavior and exception handling. - Introduced coverage configuration to omit specific files.
43 lines
976 B
Python
43 lines
976 B
Python
from threading import Event
|
|
import signal
|
|
import os
|
|
import traceback
|
|
from ingestor.ingestor import Ingestor
|
|
|
|
exit_signal = Event()
|
|
|
|
|
|
def main():
|
|
ingestor = Ingestor()
|
|
ingestor.prepare_ingestor()
|
|
ingestor.logger.info("Ingestor prepared. Starting main loop.")
|
|
|
|
while not exit_signal.is_set():
|
|
try:
|
|
ingestor.loop()
|
|
|
|
exit_signal.wait(ingestor.poll_interval)
|
|
|
|
except Exception:
|
|
print("Exception in main loop. Setting exit_signal flag.")
|
|
traceback.print_exc()
|
|
exit_signal.set()
|
|
|
|
ingestor.shutdown()
|
|
|
|
ingestor.logger.info("Main loop exit_signaled.")
|
|
|
|
os._exit(0)
|
|
|
|
|
|
def signal_handler(_signum, _frame):
|
|
print(f"Received signal {_signum}. Setting exit_signal flag.")
|
|
exit_signal.set()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
|
signal.signal(signal.SIGHUP, signal_handler)
|
|
main()
|