#!/usr/bin/env python3 """Create example jobs for testing DaemonControl. This script creates several test jobs with different schedules to demonstrate the daemon functionality. """ from datetime import datetime from core import DatabaseManager def main(): """Create test jobs.""" db = DatabaseManager() print("=" * 70) print("Creating Test Jobs for DaemonControl") print("=" * 70) print() # Job 1: Echo test (every minute) print("[1] Creating echo test job (runs every minute)...") try: job_id = db.create_job( name="echo_test", job_type="script", executable_path="/usr/bin/echo", description="Test job that echoes 'Hello from DaemonControl'" ) # Add schedule now = datetime.now().isoformat() with db.get_connection() as conn: conn.execute( "INSERT INTO schedules " "(job_id, cron_expression, enabled, created_at, updated_at) " "VALUES (?, ?, 1, ?, ?)", (job_id, "* * * * *", now, now) ) print(f" ✓ Created job ID {job_id} - runs every minute") except Exception as e: print(f" ⚠ Job may already exist: {e}") # Job 2: Date command (every 5 minutes) print("\n[2] Creating date display job (runs every 5 minutes)...") try: job_id = db.create_job( name="date_display", job_type="script", executable_path="/usr/bin/date", description="Display current date and time" ) now = datetime.now().isoformat() with db.get_connection() as conn: conn.execute( "INSERT INTO schedules " "(job_id, cron_expression, enabled, created_at, updated_at) " "VALUES (?, ?, 1, ?, ?)", (job_id, "*/5 * * * *", now, now) ) print(f" ✓ Created job ID {job_id} - runs every 5 minutes") except Exception as e: print(f" ⚠ Job may already exist: {e}") # Job 3: System info (hourly) print("\n[3] Creating system info job (runs hourly)...") try: job_id = db.create_job( name="system_info", job_type="script", executable_path="/usr/bin/uname", description="Display system information" ) now = datetime.now().isoformat() with db.get_connection() as conn: conn.execute( "INSERT INTO schedules " "(job_id, cron_expression, enabled, created_at, updated_at) " "VALUES (?, ?, 1, ?, ?)", (job_id, "0 * * * *", now, now) ) print(f" ✓ Created job ID {job_id} - runs every hour") except Exception as e: print(f" ⚠ Job may already exist: {e}") # Summary print("\n" + "=" * 70) print("Summary") print("=" * 70) jobs = db.get_enabled_jobs() job_names = set() for job in jobs: if job['name'] not in job_names: job_names.add(job['name']) print(f"\n✓ {job['name']}") print(f" Type: {job['job_type']}") print(f" Path: {job['executable_path']}") if job['cron_expression']: print(f" Schedule: {job['cron_expression']}") print("\n" + "=" * 70) print("Next Steps:") print("=" * 70) print() print("1. Install dependencies (if not already installed):") print(" pip install apscheduler PyQt6 python-dateutil") print() print("2. Start the daemon:") print(" python3 start_daemon.py") print() print("3. Watch logs:") print(" tail -f ~/.config/daemon-control/logs/daemon.log") print() print("4. Watch execution logs:") print(" tail -f ~/.config/daemon-control/logs/executions/*.log") print() if __name__ == '__main__': main()