Skip to content

Commit

Permalink
tasks remove containers after they are done
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Nov 27, 2023
1 parent 71bdab5 commit 3768295
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ func (builtin *RunPythonCapabilities) Validate(_ *builtin_argument.ArgumentValue
return validateTasksCommon(validatorEnvironment, builtin.storeSpecList, serviceDirpathsToArtifactIdentifiers, builtin.serviceConfig.GetContainerImageName())
}

// Execute This is just v0 for run_python task - we can later improve on it.
// Execute This is just v0 for run_sh 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 {
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3768295

Please sign in to comment.