diff --git a/OliveTin.proto b/OliveTin.proto index dee9078..7a20331 100644 --- a/OliveTin.proto +++ b/OliveTin.proto @@ -189,6 +189,17 @@ message EventExecutionFinished { LogEntry log_entry = 1; } +message KillActionRequest { + string execution_tracking_id = 1; +} + +message KillActionResponse { + string execution_tracking_id = 1; + bool killed = 2; + bool already_completed = 3; + bool found = 4; +} + service OliveTinApiService { rpc GetDashboardComponents(GetDashboardComponentsRequest) returns (GetDashboardComponentsResponse) { option (google.api.http) = { @@ -222,6 +233,13 @@ service OliveTinApiService { }; } + rpc KillAction(KillActionRequest) returns (KillActionResponse) { + option (google.api.http) = { + post: "/api/KillAction" + body: "*" + }; + } + rpc ExecutionStatus(ExecutionStatusRequest) returns (ExecutionStatusResponse) { option (google.api.http) = { post: "/api/ExecutionStatus" diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 2874e77..6843b8f 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -74,6 +74,7 @@ type InternalLogEntry struct { ExecutionStarted bool ExecutionFinished bool ExecutionTrackingID string + Process *os.Process /* The following 3 properties are obviously on Action normally, but it's useful @@ -382,6 +383,8 @@ func stepExec(req *ExecutionRequest) bool { runerr := cmd.Start() + req.logEntry.Process = cmd.Process + waiterr := cmd.Wait() req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode()) diff --git a/internal/grpcapi/grpcApi.go b/internal/grpcapi/grpcApi.go index e5c7592..14c30d6 100644 --- a/internal/grpcapi/grpcApi.go +++ b/internal/grpcapi/grpcApi.go @@ -30,6 +30,28 @@ type oliveTinAPI struct { executor *executor.Executor } +func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *pb.KillActionRequest) (*pb.KillActionResponse, error) { + ret := &pb.KillActionResponse{ + ExecutionTrackingId: req.ExecutionTrackingId, + } + + execReq, found := api.executor.Logs[req.ExecutionTrackingId] + + ret.Found = found + + if found { + err := execReq.Process.Kill() + + if err == nil { + ret.AlreadyCompleted = true + } else { + ret.Killed = true + } + } + + return ret, nil +} + func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest) (*pb.StartActionResponse, error) { args := make(map[string]string) diff --git a/webui.dev/index.html b/webui.dev/index.html index a116ca1..02211b6 100644 --- a/webui.dev/index.html +++ b/webui.dev/index.html @@ -125,11 +125,13 @@ -