add scheduler
This commit is contained in:
		@@ -6,6 +6,7 @@ use rusqlite::Connection;
 | 
			
		||||
use seahorse::{App, Command, Context};
 | 
			
		||||
use crate::utils::{load_config, save_config};
 | 
			
		||||
use crate::commands::db::{save_cmd, export_cmd};
 | 
			
		||||
use crate::commands::scheduler::{scheduler_cmd};
 | 
			
		||||
use crate::config::ConfigPaths;
 | 
			
		||||
use crate::agent::AIState;
 | 
			
		||||
 | 
			
		||||
@@ -92,4 +93,5 @@ pub fn cli_app() -> App {
 | 
			
		||||
        .command(talk_cmd)
 | 
			
		||||
        .command(save_cmd())
 | 
			
		||||
        .command(export_cmd())
 | 
			
		||||
        .command(scheduler_cmd())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1,2 @@
 | 
			
		||||
pub mod db;
 | 
			
		||||
pub mod scheduler;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								src/commands/scheduler.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/commands/scheduler.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
// src/commands/scheduler.rs
 | 
			
		||||
 | 
			
		||||
use seahorse::{Command, Context};
 | 
			
		||||
use std::thread;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
use chrono::Local;
 | 
			
		||||
 | 
			
		||||
pub fn scheduler_cmd() -> Command {
 | 
			
		||||
    Command::new("scheduler")
 | 
			
		||||
        .usage("scheduler [interval_sec]")
 | 
			
		||||
        .alias("s")
 | 
			
		||||
        .action(|c: &Context| {
 | 
			
		||||
            let interval = c.args.get(0)
 | 
			
		||||
                .and_then(|s| s.parse::<u64>().ok())
 | 
			
		||||
                .unwrap_or(60); // デフォルト: 60秒ごと
 | 
			
		||||
 | 
			
		||||
            println!("⏳ スケジューラー開始({interval}秒ごと)...");
 | 
			
		||||
 | 
			
		||||
            loop {
 | 
			
		||||
                let now = Local::now();
 | 
			
		||||
                println!("🔁 タスク実行中: {}", now.format("%Y-%m-%d %H:%M:%S"));
 | 
			
		||||
                
 | 
			
		||||
                // ここで talk_cmd や save_cmd の内部処理を呼ぶ感じ
 | 
			
		||||
                // たとえば load_config → AI更新 → print とか
 | 
			
		||||
 | 
			
		||||
                thread::sleep(Duration::from_secs(interval));
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user