1
0

add scheduler

This commit is contained in:
syui 2025-05-20 23:49:43 +09:00
parent f09fd0c020
commit 22d497661e
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
3 changed files with 32 additions and 0 deletions

View File

@ -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())
}

View File

@ -1 +1,2 @@
pub mod db;
pub mod scheduler;

29
src/commands/scheduler.rs Normal file
View 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));
}
})
}