diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go index e4df70e945..cb5833778d 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go @@ -276,10 +276,8 @@ func (builtin *RunPythonCapabilities) Validate(_ *builtin_argument.ArgumentValue // Execute This is just v0 for run_python task - we can later improve on it. // -// These TODOs are copied from run-sh -// TODO: stop the container as soon as task completed. -// Create an mechanism for other services to retrieve files from the task container -// Make task as its own entity instead of currently shown under services +// TODO Create an mechanism for other services to retrieve files from the task container +// TODO Make task as its own entity instead of currently shown under services func (builtin *RunPythonCapabilities) Execute(ctx context.Context, _ *builtin_argument.ArgumentValuesSet) (string, error) { _, err := builtin.serviceNetwork.AddService(ctx, service.ServiceName(builtin.name), builtin.serviceConfig) if err != nil { @@ -329,6 +327,11 @@ func (builtin *RunPythonCapabilities) Execute(ctx context.Context, _ *builtin_ar return "", stacktrace.Propagate(err, "error occurred while copying files from a task") } } + + if err = removeService(ctx, builtin.serviceNetwork, builtin.name); err != nil { + return "", stacktrace.Propagate(err, "attempted to remove the temporary task container but failed") + } + return instructionResult, err } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go index fc81a46793..fbdb8363ca 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go @@ -188,9 +188,8 @@ func (builtin *RunShCapabilities) Validate(_ *builtin_argument.ArgumentValuesSet // Execute This is just v0 for run_sh task - we can later improve on it. // -// TODO: stop the container as soon as task completed. -// Create an mechanism for other services to retrieve files from the task container -// Make task as its own entity instead of currently shown under services +// TODO Create an mechanism for other services to retrieve files from the task container +// Make task as its own entity instead of currently shown under services func (builtin *RunShCapabilities) Execute(ctx context.Context, _ *builtin_argument.ArgumentValuesSet) (string, error) { _, err := builtin.serviceNetwork.AddService(ctx, service.ServiceName(builtin.name), builtin.serviceConfig) if err != nil { @@ -232,6 +231,11 @@ func (builtin *RunShCapabilities) Execute(ctx context.Context, _ *builtin_argume return "", stacktrace.Propagate(err, "error occurred while copying files from a task") } } + + if err = removeService(ctx, builtin.serviceNetwork, builtin.name); err != nil { + return "", stacktrace.Propagate(err, "attempted to remove the temporary task container but failed") + } + return instructionResult, err } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go index 3804ac1a4e..9f4b96b72c 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go @@ -279,3 +279,11 @@ func formatErrorMessage(errorMessage string, errorFromExec string) string { reformattedErrorMessage := strings.Join(splitErrorMessageNewLine, "\n ") return fmt.Sprintf("%v\n %v", errorMessage, reformattedErrorMessage) } + +func removeService(ctx context.Context, serviceNetwork service_network.ServiceNetwork, serviceName string) error { + _, err := serviceNetwork.RemoveService(ctx, serviceName) + if err != nil { + return stacktrace.NewError("error occurred while removing task with name %v", serviceName) + } + return nil +}