#!/usr/bin/env python3 """Example usage of DaemonControl foundation infrastructure. This script demonstrates how to use the core modules: - ConfigManager for configuration - DatabaseManager for job management - setup_logger for logging """ from datetime import datetime from core import DatabaseManager, ConfigManager, setup_logger def main(): """Demonstrate DaemonControl core functionality.""" # Setup logger logger = setup_logger('example', None, 'INFO') logger.info("Starting DaemonControl example") # Initialize config and database config = ConfigManager() db = DatabaseManager() logger.info(f"Database path: {config.get('database', 'path')}") logger.info(f"Schema version: {db.get_schema_version()}") # Create a sample job try: job_id = db.create_job( name="example_backup", job_type="script", executable_path="/usr/bin/rsync", working_directory="/home/user/backups", timeout=3600, description="Daily backup to external drive" ) logger.info(f"Created job 'example_backup' with ID: {job_id}") except Exception as e: logger.warning(f"Job might already exist: {e}") # List all enabled jobs jobs = db.get_enabled_jobs() logger.info(f"Found {len(jobs)} enabled job(s):") for job in jobs: logger.info(f" - {job['name']} ({job['job_type']}): {job['executable_path']}") # Simulate job execution if jobs: job = jobs[0] exec_id = db.create_execution(job['id'], 'running') logger.info(f"Started execution {exec_id} for job '{job['name']}'") # Simulate completion db.update_execution( exec_id, status='success', exit_code=0, end_time=datetime.now().isoformat() ) logger.info(f"Execution {exec_id} completed successfully") logger.info("Example completed!") if __name__ == '__main__': main()