Skip to main content

systemprompt_cli/commands/infrastructure/jobs/
mod.rs

1//! `jobs` CLI command group: list, inspect, run, and manage scheduled jobs.
2//!
3//! [`JobsCommands`] enumerates the subcommands; [`execute`] dispatches each to
4//! its submodule and renders the result. Includes manual job runs, history,
5//! enable/disable toggles, and the session/log cleanup helpers.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10pub mod types;
11
12pub mod cleanup_logs;
13pub mod cleanup_sessions;
14mod disable;
15mod enable;
16mod helpers;
17pub mod history;
18mod list;
19mod run;
20mod show;
21
22use anyhow::Result;
23use clap::Subcommand;
24
25use crate::context::CommandContext;
26use crate::shared::render_result;
27
28use systemprompt_generator as _;
29
30#[derive(Debug, Subcommand)]
31pub enum JobsCommands {
32    #[command(about = "List available jobs")]
33    List,
34
35    #[command(about = "Show detailed information about a job")]
36    Show(show::ShowArgs),
37
38    #[command(about = "Run a scheduled job manually")]
39    Run(run::RunArgs),
40
41    #[command(about = "View job execution history")]
42    History(history::HistoryArgs),
43
44    #[command(about = "Enable a job")]
45    Enable(enable::EnableArgs),
46
47    #[command(about = "Disable a job")]
48    Disable(disable::DisableArgs),
49
50    #[command(about = "Clean up inactive sessions")]
51    CleanupSessions(cleanup_sessions::CleanupSessionsArgs),
52
53    #[command(about = "Clean up old log entries")]
54    LogCleanup(cleanup_logs::LogCleanupArgs),
55
56    #[command(about = "Clean up inactive sessions (alias)", hide = true)]
57    SessionCleanup(cleanup_sessions::CleanupSessionsArgs),
58}
59
60pub async fn execute(cmd: JobsCommands, ctx: &CommandContext) -> Result<()> {
61    match cmd {
62        JobsCommands::List => {
63            render_result(&list::execute(), &ctx.cli);
64            Ok(())
65        },
66        JobsCommands::Show(args) => {
67            render_result(&show::execute(args, ctx).await?, &ctx.cli);
68            Ok(())
69        },
70        JobsCommands::Run(args) => {
71            render_result(&run::execute(args, ctx).await?, &ctx.cli);
72            Ok(())
73        },
74        JobsCommands::History(args) => {
75            render_result(&history::execute(args, ctx).await?, &ctx.cli);
76            Ok(())
77        },
78        JobsCommands::Enable(args) => {
79            render_result(&enable::execute(args, ctx).await?, &ctx.cli);
80            Ok(())
81        },
82        JobsCommands::Disable(args) => {
83            render_result(&disable::execute(args, ctx).await?, &ctx.cli);
84            Ok(())
85        },
86        JobsCommands::CleanupSessions(args) | JobsCommands::SessionCleanup(args) => {
87            render_result(&cleanup_sessions::execute(args, ctx).await?, &ctx.cli);
88            Ok(())
89        },
90        JobsCommands::LogCleanup(args) => {
91            render_result(&cleanup_logs::execute(args, ctx).await?, &ctx.cli);
92            Ok(())
93        },
94    }
95}