TaskStatusOverNetwork fetches the status of a task over the network. Alphas only know about the tasks created by them, but this function would fetch the task from the correct Alpha.
(ctx context.Context, req *pb.TaskStatusRequest, )
| 28 | // TaskStatusOverNetwork fetches the status of a task over the network. Alphas only know about the |
| 29 | // tasks created by them, but this function would fetch the task from the correct Alpha. |
| 30 | func TaskStatusOverNetwork(ctx context.Context, req *pb.TaskStatusRequest, |
| 31 | ) (*pb.TaskStatusResponse, error) { |
| 32 | // Extract Raft ID from Task ID. |
| 33 | taskId := req.GetTaskId() |
| 34 | if taskId == 0 { |
| 35 | return nil, fmt.Errorf("invalid task ID: %#x", taskId) |
| 36 | } |
| 37 | raftId := taskId >> 32 |
| 38 | |
| 39 | // Skip the network call if the required Alpha is me. |
| 40 | myRaftId := State.WALstore.Uint(raftwal.RaftId) |
| 41 | if raftId == myRaftId { |
| 42 | worker := (*grpcWorker)(nil) |
| 43 | return worker.TaskStatus(ctx, req) |
| 44 | } |
| 45 | |
| 46 | // Find the Alpha with the required Raft ID. |
| 47 | var addr string |
| 48 | for _, group := range groups().state.GetGroups() { |
| 49 | for _, member := range group.GetMembers() { |
| 50 | if member.GetId() == raftId { |
| 51 | addr = member.GetAddr() |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | if addr == "" { |
| 56 | return nil, fmt.Errorf("the Alpha that served that task is not available") |
| 57 | } |
| 58 | |
| 59 | // Send the request to the Alpha. |
| 60 | pool, err := conn.GetPools().Get(addr) |
| 61 | if err != nil { |
| 62 | return nil, errors.Wrapf(err, "unable to reach the Alpha that served that task") |
| 63 | } |
| 64 | client := pb.NewWorkerClient(pool.Get()) |
| 65 | return client.TaskStatus(ctx, req) |
| 66 | } |
| 67 | |
| 68 | // TaskStatus retrieves metadata for a given task ID. |
| 69 | func (*grpcWorker) TaskStatus(ctx context.Context, req *pb.TaskStatusRequest, |
no test coverage detected