Fix database initialization errors - add error handling to scheduler and CLI status command

This commit is contained in:
Jarian Cottingham 2026-02-02 21:24:23 -06:00
parent eddfa7cb8e
commit 7d785538fc
3 changed files with 35 additions and 18 deletions

View File

@ -54,22 +54,26 @@ def onboard(directory: str, table_name: str, prompt: Optional[str], model: str,
def status():
"""Show current status and scheduled jobs"""
config = Config()
scheduler = get_scheduler(config)
try:
scheduler = get_scheduler(config)
click.echo("FactsDB Service Status")
click.echo("=" * 30)
click.echo("FactsDB Service Status")
click.echo("=" * 30)
jobs = scheduler.get_jobs()
if jobs:
click.echo("Scheduled Jobs:")
for i, job in enumerate(jobs, 1):
click.echo(f" {i}. Directory: {job['directory_path']}")
click.echo(f" Table: {job['table_name']}")
click.echo(f" Model: {job['model']}")
click.echo(f" Interval: {job['interval_minutes']} minutes")
click.echo()
else:
click.echo("No scheduled jobs")
jobs = scheduler.get_jobs()
if jobs:
click.echo("Scheduled Jobs:")
for i, job in enumerate(jobs, 1):
click.echo(f" {i}. Directory: {job['directory_path']}")
click.echo(f" Table: {job['table_name']}")
click.echo(f" Model: {job['model']}")
click.echo(f" Interval: {job['interval_minutes']} minutes")
click.echo()
else:
click.echo("No scheduled jobs")
except Exception as e:
click.echo(f"Error getting scheduler status: {str(e)}")
click.echo("Scheduler may not be initialized due to database configuration issues.")
@cli.command()
@click.option('--host', '-h', default='0.0.0.0', help='FTP server host')

View File

@ -16,7 +16,13 @@ class DatabaseManager:
def __init__(self, config):
self.config = config
self._lock = threading.Lock()
self._init_database()
# Fix: Add error handling for database initialization
try:
self._init_database()
except Exception as e:
print(f"Warning: Database initialization failed: {e}")
# Continue with minimal functionality or raise the error
raise
def _init_database(self):
"""Initialize the database and create tables if they don't exist"""

View File

@ -93,7 +93,14 @@ class FactExtractionScheduler:
self.is_running = False
self.file_processor = FileProcessor()
self.ai_processor = AIProcessor(config.ai_endpoint)
self.db_manager = DatabaseManager(config.database)
# Fix: Add error handling for database initialization in scheduler
try:
self.db_manager = DatabaseManager(config.database)
except Exception as e:
print(f"Warning: Scheduler database initialization failed: {e}")
# Create a minimal database manager or handle gracefully
# For now, we'll skip database initialization for scheduler status
self.db_manager = None
def start(self):
"""Start the scheduler"""