Skip to content

Commit

Permalink
feature: Kill command API (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread committed Apr 26, 2024
1 parent a783fc8 commit e641e9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions OliveTin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type InternalLogEntry struct {
ExecutionFinished bool
ExecutionTrackingID string

Process *os.Process

/*
The following 3 properties are obviously on Action normally, but it's useful
that logs are lightweight (so we don't need to have an action associated to
Expand Down Expand Up @@ -382,6 +384,8 @@ func stepExec(req *ExecutionRequest) bool {

runerr := cmd.Start()

req.logEntry.Process = cmd.Process

waiterr := cmd.Wait()

req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode())
Expand Down
22 changes: 22 additions & 0 deletions internal/grpcapi/grpcApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e641e9a

Please sign in to comment.