Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions crates/slingshot-cli/src/watch/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ fn resource(title: String, body: String) -> Notice {
}

/// What a finished job is worth saying. The command is the subtitle, so the title can stay
/// short and plain. Stopping is something the person just did, and a session usually ends
/// because someone left it, so only surprises about those are told.
/// short and plain. Stopping is something the person just did, whether with `slingshot stop`
/// or with Ctrl C, which ends a run with exit code 130. A session usually ends because
/// someone left it. So only surprises about those are told.
fn notice(name: &str, job: &Job) -> Option<Notice> {
let took = job.ended?.saturating_sub(job.started);
let place = job
Expand All @@ -204,6 +205,7 @@ fn notice(name: &str, job: &Job) -> Option<Notice> {
JobKind::Session => "Session".to_string(),
};
let (kind, title, body) = match (job.kind, job.state) {
(JobKind::Run, JobState::Interrupted) if job.exit_code == Some(130) => return None,
(_, JobState::Interrupted) => (
NoticeKind::JobInterrupted,
format!("Interrupted on {name}"),
Expand Down Expand Up @@ -388,6 +390,18 @@ mod tests {
);
}

#[test]
fn ctrl_c_is_not_told_but_a_lost_connection_is() {
let mut watch = Watch::new("archbox");
watch.jobs(&[]);
let mut ctrl_c = run("a", JobState::Interrupted, 30);
ctrl_c.exit_code = Some(130);
let lost = run("b", JobState::Interrupted, 30);
let notices = watch.jobs(&[ctrl_c, lost]);
assert_eq!(notices.len(), 1);
assert!(notices[0].body.contains("The connection dropped"));
}

#[test]
fn long_commands_are_shortened() {
let long = "x".repeat(60);
Expand Down
2 changes: 1 addition & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ slingshot env remove .env

* Shows the Agent, connection, CPU, RAM, GPU, VRAM, and project space.
* When the Agent is unreachable, shows why and the fix.
* Notifies when a run of 10 seconds or more ends, a job is interrupted, the Agent goes offline or returns, or memory, disk, or GPU heat needs attention.
* Notifies when a run of 10 seconds or more ends, a job is cut off by a lost connection or restart, the Agent goes offline or returns, or memory, disk, or GPU heat needs attention.
* No notifications? Turn them on in System Settings, Notifications, Slingshot.

## More Than One Agent
Expand Down
Loading