extract jobkit-daemon library from poc-memory daemon
Create jobkit-daemon crate with generic daemon infrastructure: - event_log: JSONL append with size-based rotation - socket: Unix domain socket RPC client and server with signal handling - status: JSON status file read/write Migrate daemon.rs to use the library: - Worker pool setup via Daemon::new() - Socket loop + signal handling via Daemon::run() - RPC handlers as registered closures - Logging, status writing, send_rpc all delegate to library Migrate tui.rs to use socket::send_rpc() instead of inline UnixStream. daemon.rs: 1952 → 1806 lines (-146), old status_socket_loop removed. tui.rs: socket boilerplate removed. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
35bc93c22b
commit
420a777eba
11 changed files with 696 additions and 293 deletions
|
|
@ -22,8 +22,6 @@ use ratatui::{
|
|||
DefaultTerminal, Frame,
|
||||
};
|
||||
use std::fs;
|
||||
use std::io::Read as _;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
|
@ -35,10 +33,6 @@ const AGENT_TYPES: &[&str] = &[
|
|||
"apply", "orphans", "cap", "digest", "digest-links", "knowledge", "rename", "split",
|
||||
];
|
||||
|
||||
fn status_sock_path() -> PathBuf {
|
||||
crate::config::get().data_dir.join("daemon.sock")
|
||||
}
|
||||
|
||||
fn log_path() -> PathBuf {
|
||||
crate::config::get().data_dir.join("daemon.log")
|
||||
}
|
||||
|
|
@ -58,11 +52,8 @@ struct DaemonStatus {
|
|||
}
|
||||
|
||||
fn fetch_status() -> Option<DaemonStatus> {
|
||||
let mut stream = UnixStream::connect(status_sock_path()).ok()?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(2))).ok();
|
||||
let mut buf = String::new();
|
||||
stream.read_to_string(&mut buf).ok()?;
|
||||
serde_json::from_str(&buf).ok()
|
||||
let json = jobkit_daemon::socket::send_rpc(&crate::config::get().data_dir, "")?;
|
||||
serde_json::from_str(&json).ok()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -794,14 +785,7 @@ fn short_name(name: &str) -> String {
|
|||
}
|
||||
|
||||
fn send_rpc(cmd: &str) -> Option<String> {
|
||||
let mut stream = UnixStream::connect(status_sock_path()).ok()?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(2))).ok();
|
||||
stream.set_read_timeout(Some(Duration::from_secs(5))).ok();
|
||||
std::io::Write::write_all(&mut stream, cmd.as_bytes()).ok()?;
|
||||
stream.shutdown(std::net::Shutdown::Write).ok()?;
|
||||
let mut buf = String::new();
|
||||
stream.read_to_string(&mut buf).ok()?;
|
||||
Some(buf)
|
||||
jobkit_daemon::socket::send_rpc(&crate::config::get().data_dir, cmd)
|
||||
}
|
||||
|
||||
// --- Entry point ---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue