Show what went wrong when an entry is put on hold

This commit is contained in:
Mustafa Gezen 2023-08-31 10:37:47 +02:00
parent 52115456cb
commit a562752457
Signed by: mustafa
GPG Key ID: DCDF010D946438C1
3 changed files with 45 additions and 10 deletions

View File

@ -66,7 +66,7 @@ export const GetEntry = () => {
}
window.location.reload();
}
};
return (
<Box>
@ -80,13 +80,15 @@ export const GetEntry = () => {
}}
>
<span>entries/{params.name}</span>
{resource && resource.state == EntryState.OnHold && <Button
sx={{ ml: 'auto', textAlign: 'right' }}
variant="outlined"
onClick={rescueEntry}
>
Rescue
</Button>}
{resource && resource.state == EntryState.OnHold && (
<Button
sx={{ ml: 'auto', textAlign: 'right' }}
variant="outlined"
onClick={rescueEntry}
>
Rescue
</Button>
)}
</Box>
<Divider />
<Box sx={{ p: 1.5 }}>
@ -105,6 +107,11 @@ export const GetEntry = () => {
]}
/>
</Box>
{resource && resource.state == EntryState.OnHold && (
<Box sx={{ p: 1.5 }}>
<code>{resource.errorMessage}</code>
</Box>
)}
</Box>
);
};

View File

@ -101,4 +101,7 @@ message Entry {
}
// State of the entry.
State state = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
// Error message if on hold
string error_message = 13 [(google.api.field_behavior) = OUTPUT_ONLY];
}

View File

@ -20,11 +20,12 @@ import (
base "go.resf.org/peridot/base/go"
mothership_db "go.resf.org/peridot/tools/mothership/db"
mothershippb "go.resf.org/peridot/tools/mothership/pb"
enumspb "go.temporal.io/api/enums/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *Server) GetEntry(_ context.Context, req *mothershippb.GetEntryRequest) (*mothershippb.Entry, error) {
func (s *Server) GetEntry(ctx context.Context, req *mothershippb.GetEntryRequest) (*mothershippb.Entry, error) {
entry, err := base.Q[mothership_db.Entry](s.db).F("name", req.Name).GetOrNil()
if err != nil {
base.LogErrorf("failed to get entry: %v", err)
@ -35,7 +36,31 @@ func (s *Server) GetEntry(_ context.Context, req *mothershippb.GetEntryRequest)
return nil, status.Error(codes.NotFound, "entry not found")
}
return entry.ToPB(), nil
pb := entry.ToPB()
// If on hold, let's query temporal for more info.
if entry.State == mothershippb.Entry_ON_HOLD {
events := s.temporal.GetWorkflowHistory(ctx, "operations/"+entry.Sha256Sum, "", false, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
// We only need to find the latest ImportRPM event.
// Return the error from that event.
pb.ErrorMessage = "Unknown error"
for events.HasNext() {
event, err := events.Next()
if err != nil {
base.LogErrorf("failed to get next event: %v", err)
continue
}
failedAttrs := event.GetActivityTaskFailedEventAttributes()
if failedAttrs == nil {
continue
}
pb.ErrorMessage = failedAttrs.Failure.Message
break
}
}
return pb, nil
}
func (s *Server) ListEntries(_ context.Context, req *mothershippb.ListEntriesRequest) (*mothershippb.ListEntriesResponse, error) {