Skip to content

examples/long-running-process: Add reset #21995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
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
6 changes: 4 additions & 2 deletions examples/long-running-process/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function update(process) {
showJournal(process.serviceName, "--since=@" + Math.floor(process.startTimestamp / 1000000));
break;
case ProcessState.FAILED:
run_button.setAttribute("disabled", "");
run_button.textContent = "Start";
run_button.removeAttribute("disabled");
run_button.textContent = "Reset";
// Show the whole journal of this boot
showJournal(process.serviceName, "--boot");
break;
Expand Down Expand Up @@ -74,6 +74,8 @@ cockpit.transport.wait(() => {
run_button.addEventListener("click", () => {
if (process.state === ProcessState.RUNNING)
process.terminate();
else if (process.state === ProcessState.FAILED)
process.reset();
else
process.run(["/bin/sh", "-ec", command.value])
.catch(ex => {
Expand Down
6 changes: 6 additions & 0 deletions pkg/lib/long-running-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class LongRunningProcess {
return this.systemdClient.call(O_SD_OBJ, I_SD_MGR, "StopUnit", [this.serviceName, "replace"], { type: "ss" });
}

reset() {
if (this.state === ProcessState.FAILED)
this.systemdClient.call(O_SD_OBJ, I_SD_MGR, "ResetFailedUnit", [this.serviceName], { type: "s" });
else
throw new Error(`cannot reset LongRuningProcess in state ${this.state}`);
}
/*
* below are internal private methods
*/
Expand Down
7 changes: 3 additions & 4 deletions test/verify/check-examples
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class TestLongRunning(testlib.MachineCase):
self.assertNotIn("\nNOTME", out)
# does not contain previous logs
self.assertNotIn("STEP_B", out)
b.wait_text("button#run", "Start")
b.wait_text("button#run", "Reset")

# failing state gets picked up on page reconnect
b.logout()
Expand All @@ -160,11 +160,10 @@ class TestLongRunning(testlib.MachineCase):
out = b.text("#output")
self.assertIn("\nBREAK_A\n", out)
self.assertNotIn("\nNOTME", out)
b.wait_visible("button#run:disabled")
b.wait_text("button#run", "Start")
b.wait_text("button#run", "Reset")

# reset
m.execute("systemctl reset-failed cockpit-longrunning.service")
b.click("button#run")
b.wait_text("#state", "cockpit-longrunning.service stopped")

# cancel long-running command
Expand Down