Skip to content

Commit

Permalink
api/cancel: handle event in compute backend first to allow for state …
Browse files Browse the repository at this point in the history
…check
  • Loading branch information
adamstruck authored and buchanae committed Feb 12, 2018
1 parent b01be14 commit 0de7f8b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions server/tes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@ func (ts *TaskService) ListTasks(ctx context.Context, req *tes.ListTasksRequest)

// CancelTask cancels a task
func (ts *TaskService) CancelTask(ctx context.Context, req *tes.CancelTaskRequest) (*tes.CancelTaskResponse, error) {
// dispatch to compute backend
err := ts.Compute.WriteEvent(ctx, events.NewState(req.Id, tes.Canceled))
if err != nil {
ts.Log.Error("compute backend failed to cancel task", "taskID", req.Id, "error", err)
}

// updated database and other event streams
err := ts.Event.WriteEvent(ctx, events.NewState(req.Id, tes.Canceled))
err = ts.Event.WriteEvent(ctx, events.NewState(req.Id, tes.Canceled))
if err == tes.ErrNotFound {
err = grpc.Errorf(codes.NotFound, fmt.Sprintf("%v: taskID: %s", err.Error(), req.Id))
}

// dispatch to compute backend
cerr := ts.Compute.WriteEvent(ctx, events.NewState(req.Id, tes.Canceled))
if cerr != nil {
ts.Log.Error("compute backend failed to cancel task %s: %v", req.Id, cerr)
}

return &tes.CancelTaskResponse{}, err
}

Expand Down

0 comments on commit 0de7f8b

Please sign in to comment.