From 22d497661ef1b09e23bbf5ef27bf1c44c046693a Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 20 May 2025 23:49:43 +0900 Subject: [PATCH] add scheduler --- src/cli.rs | 2 ++ src/commands/mod.rs | 1 + src/commands/scheduler.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/commands/scheduler.rs diff --git a/src/cli.rs b/src/cli.rs index f6c90d7..fd1c926 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index dec1023..2a4d3bc 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1 +1,2 @@ pub mod db; +pub mod scheduler; diff --git a/src/commands/scheduler.rs b/src/commands/scheduler.rs new file mode 100644 index 0000000..fe185f0 --- /dev/null +++ b/src/commands/scheduler.rs @@ -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::().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)); + } + }) +}