Skip to content

Commit d8ca04f

Browse files
TypicalRenegademartinpitt
authored andcommitted
examples/long-running-process: Add reset
When a launched process has failed, the run button will change to "Reset" and will reset the unit so it can be ran again.
1 parent d5ec39c commit d8ca04f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

examples/long-running-process/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function update(process) {
4040
showJournal(process.serviceName, "--since=@" + Math.floor(process.startTimestamp / 1000000));
4141
break;
4242
case ProcessState.FAILED:
43-
run_button.setAttribute("disabled", "");
44-
run_button.textContent = "Start";
43+
run_button.removeAttribute("disabled");
44+
run_button.textContent = "Reset";
4545
// Show the whole journal of this boot
4646
showJournal(process.serviceName, "--boot");
4747
break;
@@ -74,6 +74,8 @@ cockpit.transport.wait(() => {
7474
run_button.addEventListener("click", () => {
7575
if (process.state === ProcessState.RUNNING)
7676
process.terminate();
77+
else if (process.state === ProcessState.FAILED)
78+
process.reset();
7779
else
7880
process.run(["/bin/sh", "-ec", command.value])
7981
.catch(ex => {

pkg/lib/long-running-process.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export class LongRunningProcess {
9191
return this.systemdClient.call(O_SD_OBJ, I_SD_MGR, "StopUnit", [this.serviceName, "replace"], { type: "ss" });
9292
}
9393

94+
reset() {
95+
if (this.state === ProcessState.FAILED)
96+
this.systemdClient.call(O_SD_OBJ, I_SD_MGR, "ResetFailedUnit", [this.serviceName], { type: "s" });
97+
else
98+
throw new Error(`cannot reset LongRuningProcess in state ${this.state}`);
99+
}
94100
/*
95101
* below are internal private methods
96102
*/

test/verify/check-examples

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class TestLongRunning(testlib.MachineCase):
150150
self.assertNotIn("\nNOTME", out)
151151
# does not contain previous logs
152152
self.assertNotIn("STEP_B", out)
153-
b.wait_text("button#run", "Start")
153+
b.wait_text("button#run", "Reset")
154154

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

166165
# reset
167-
m.execute("systemctl reset-failed cockpit-longrunning.service")
166+
b.click("button#run")
168167
b.wait_text("#state", "cockpit-longrunning.service stopped")
169168

170169
# cancel long-running command

0 commit comments

Comments
 (0)