|
43 | 43 |
|
44 | 44 | @app.on_event("startup") |
45 | 45 | def _startup() -> None: |
46 | | - """ |
47 | | - Initialize application on startup with comprehensive error handling. |
48 | | - """ |
49 | | - # Initialize database with error recovery |
| 46 | + """Initialize application on startup.""" |
50 | 47 | try: |
51 | 48 | init_db() |
52 | | - print("✓ Database initialized successfully") |
53 | | - except Exception as e: |
54 | | - print(f"✗ Database initialization failed: {e}") |
55 | | - print(" Continuing anyway - some features may not work") |
| 49 | + except Exception: |
| 50 | + pass |
56 | 51 |
|
57 | | - # Auto-discovery: scan repositories folder on startup |
58 | 52 | if settings.auto_discovery_enabled and settings.repositories_folder: |
59 | 53 | try: |
60 | | - if not settings.repositories_folder.exists(): |
61 | | - print(f"⚠ Auto-discovery folder not found: {settings.repositories_folder}") |
62 | | - print(" Creating folder...") |
63 | | - settings.repositories_folder.mkdir(parents=True, exist_ok=True) |
64 | | - print(f"✓ Created: {settings.repositories_folder}") |
65 | | - |
66 | 54 | if settings.repositories_folder.exists(): |
67 | | - print(f"🔍 Auto-discovery: scanning {settings.repositories_folder}") |
68 | | - try: |
69 | | - with Session(engine) as session: |
70 | | - existing_services = list(session.exec(select(Service))) |
71 | | - existing_ports = {s.port for s in existing_services if s.port is not None} |
72 | | - existing_names = {s.name for s in existing_services} |
73 | | - |
74 | | - bundles = scan_repository_folder(str(settings.repositories_folder), existing_ports) |
75 | | - |
76 | | - # Only import new services |
77 | | - imported = 0 |
78 | | - for bundle in bundles: |
79 | | - if bundle.service.name not in existing_names: |
80 | | - try: |
81 | | - import_bundle(session, bundle) |
82 | | - imported += 1 |
83 | | - print(f" ✓ Imported: {bundle.service.name}") |
84 | | - except Exception as e: |
85 | | - print(f" ✗ Failed to import {bundle.service.name}: {e}") |
86 | | - |
87 | | - session.commit() |
88 | | - print(f"✓ Auto-discovery: imported {imported} new services") |
89 | | - except Exception as e: |
90 | | - print(f"✗ Auto-discovery failed: {e}") |
91 | | - except Exception as e: |
92 | | - print(f"✗ Auto-discovery setup failed: {e}") |
93 | | - |
94 | | - # File watcher: start watching for ZIP files |
| 55 | + with Session(engine) as session: |
| 56 | + existing_services = list(session.exec(select(Service))) |
| 57 | + existing_ports = {s.port for s in existing_services if s.port is not None} |
| 58 | + existing_names = {s.name for s in existing_services} |
| 59 | + |
| 60 | + bundles = scan_repository_folder(str(settings.repositories_folder), existing_ports) |
| 61 | + |
| 62 | + for bundle in bundles: |
| 63 | + if bundle.service.name not in existing_names: |
| 64 | + try: |
| 65 | + import_bundle(session, bundle) |
| 66 | + except Exception: |
| 67 | + pass |
| 68 | + |
| 69 | + session.commit() |
| 70 | + except Exception: |
| 71 | + pass |
| 72 | + |
95 | 73 | if settings.file_watcher_enabled and settings.file_watcher_folder and settings.repositories_folder: |
96 | 74 | try: |
97 | | - if not settings.file_watcher_folder.exists(): |
98 | | - print(f"⚠ File watcher folder not found: {settings.file_watcher_folder}") |
99 | | - print(" File watcher will not start until folder exists") |
100 | | - elif not settings.repositories_folder.exists(): |
101 | | - print(f"⚠ Repositories folder not found: {settings.repositories_folder}") |
102 | | - print(" Creating folder for extracted programs...") |
103 | | - settings.repositories_folder.mkdir(parents=True, exist_ok=True) |
104 | | - else: |
| 75 | + if settings.file_watcher_folder.exists() and settings.repositories_folder.exists(): |
105 | 76 | start_file_watcher( |
106 | 77 | str(settings.file_watcher_folder), |
107 | 78 | str(settings.repositories_folder), |
108 | 79 | ) |
109 | | - print(f"✓ File watcher started: {settings.file_watcher_folder}") |
110 | | - except Exception as e: |
111 | | - print(f"✗ File watcher failed to start: {e}") |
| 80 | + except Exception: |
| 81 | + pass |
112 | 82 |
|
113 | | - # Auto-start all services on boot |
114 | 83 | if settings.auto_start_all_on_boot: |
115 | 84 | try: |
116 | | - print("🚀 Auto-start: starting all services") |
117 | 85 | with Session(engine) as session: |
118 | 86 | services = list(session.exec(select(Service))) |
119 | | - started = 0 |
120 | | - failed = 0 |
121 | | - |
122 | 87 | for svc in services: |
123 | 88 | if svc.start_command and svc.status != "running": |
124 | 89 | try: |
125 | 90 | start_service(session, svc) |
126 | | - started += 1 |
127 | | - print(f" ✓ Started: {svc.name}") |
128 | | - except Exception as e: |
129 | | - failed += 1 |
130 | | - print(f" ✗ Failed to start {svc.name}: {e}") |
131 | | - |
| 91 | + except Exception: |
| 92 | + pass |
132 | 93 | session.commit() |
133 | | - print(f"✓ Auto-start complete: {started} started, {failed} failed") |
134 | | - except Exception as e: |
135 | | - print(f"✗ Auto-start failed: {e}") |
| 94 | + except Exception: |
| 95 | + pass |
0 commit comments