(ctx context.Context, opts ...ProcessDeleteOpts)
| 230 | } |
| 231 | |
| 232 | func (p *process) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStatus, error) { |
| 233 | ctx, span := tracing.StartSpan(ctx, "process.Delete", |
| 234 | tracing.WithAttribute("process.id", p.ID()), |
| 235 | ) |
| 236 | defer span.End() |
| 237 | for _, o := range opts { |
| 238 | if err := o(ctx, p); err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | } |
| 242 | status, err := p.Status(ctx) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | switch status.Status { |
| 247 | case Running, Paused, Pausing: |
| 248 | return nil, fmt.Errorf("current process state: %s, process must be stopped before deletion: %w", status.Status, errdefs.ErrFailedPrecondition) |
| 249 | } |
| 250 | r, err := p.task.client.TaskService().DeleteProcess(ctx, &tasks.DeleteProcessRequest{ |
| 251 | ContainerID: p.task.id, |
| 252 | ExecID: p.id, |
| 253 | }) |
| 254 | if err != nil { |
| 255 | return nil, errgrpc.ToNative(err) |
| 256 | } |
| 257 | if p.io != nil { |
| 258 | p.io.Cancel() |
| 259 | p.io.Wait() |
| 260 | p.io.Close() |
| 261 | } |
| 262 | return &ExitStatus{code: r.ExitStatus, exitedAt: protobuf.FromTimestamp(r.ExitedAt)}, nil |
| 263 | } |
| 264 | |
| 265 | func (p *process) Status(ctx context.Context) (Status, error) { |
| 266 | r, err := p.task.client.TaskService().Get(ctx, &tasks.GetRequest{ |
nothing calls this directly
no test coverage detected