Skip to content

Commit

Permalink
update view to show retries, better pay response
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed May 16, 2024
1 parent 2c931d7 commit b925a59
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const ErrorSummary = styled(Box)(({ theme }) => ({
border: `5px solid ${theme.palette.error.main}`,
}));

const Response = styled(Box)(({ theme }) => ({
fontSize: "1em",
margin: 1,
maxWidth: "contentWrap",
overflowWrap: "break-word",
whiteSpace: "pre-wrap",
}));

const EventsLog: React.FC<GetSubmissionsResponse> = ({
submissions,
loading,
Expand Down Expand Up @@ -60,13 +68,13 @@ const EventsLog: React.FC<GetSubmissionsResponse> = ({
<TableCell sx={{ width: 240 }}>
<strong>Event</strong>
</TableCell>
<TableCell sx={{ width: 120 }}>
<TableCell sx={{ width: 130 }}>
<strong>Status</strong>
</TableCell>
<TableCell sx={{ width: 120 }}>
<TableCell sx={{ width: 130 }}>
<strong>Date</strong>
</TableCell>
<TableCell sx={{ width: 370 }}>
<TableCell sx={{ width: 350 }}>
<strong>Session ID</strong>
</TableCell>
<TableCell sx={{ width: 60 }}></TableCell>
Expand Down Expand Up @@ -108,6 +116,13 @@ const CollapsibleRow: React.FC<Submission> = (submission) => {
) : (
<Chip label={submission.status} size="small" color="error" />
)}
{submission.retry && (
<Chip
label="Retry"
size="small"
sx={{ marginTop: 0.5, background: "#ddd" }}
/>
)}
</TableCell>
<TableCell>
{format(new Date(submission.createdAt), "dd/MM/yy hh:mm:ss")}
Expand Down Expand Up @@ -146,32 +161,21 @@ const CollapsibleRow: React.FC<Submission> = (submission) => {
const FormattedResponse: React.FC<Submission> = (submission) => {
if (submission.eventType === "Pay") {
return (
<Box sx={{ margin: 1 }}>
<Typography variant="body2">
{`GOV.UK Pay reference: ${submission.eventId}`}
</Typography>
</Box>
<Response component="pre">
{JSON.stringify(submission.response, null, 2)}
</Response>
);
} else {
return (
<Box
component="pre"
sx={{
fontSize: "1em",
margin: 1,
maxWidth: "contentWrap",
overflowWrap: "break-word",
whiteSpace: "pre-wrap",
}}
>
<Response component="pre">
{submission.status === "Success"
? JSON.stringify(JSON.parse(submission.response?.data?.body), null, 2)
: JSON.stringify(
JSON.parse(submission.response?.data?.message),
null,
2,
)}
</Box>
</Response>
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ export interface Submission {
| "Upload to AWS S3";
status?:
| "Success"
| "Failed (500)"
| "Failed (500)" // Hasura scheduled event status codes
| "Failed (502)"
| "Failed (503)"
| "Failed (504)"
| "Failed (400)"
| "Failed (401)";
| "Failed (401)"
| "Started" // Payment status enum codes (excluding "Created")
| "Submitted"
| "Capturable"
| "Failed"
| "Cancelled"
| "Error"
| "Unknown";
retry: boolean;
response: Record<string, any>;
createdAt: string;
}
Expand All @@ -49,6 +57,7 @@ const Submissions: React.FC = () => {
eventId: event_id
eventType: event_type
status: status
retry: retry
response: response
createdAt: created_at
}
Expand Down
2 changes: 2 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@
- role: platformAdmin
permission:
columns:
- retry
- response
- event_id
- event_type
Expand All @@ -1379,6 +1380,7 @@
- role: teamEditor
permission:
columns:
- retry
- response
- event_id
- event_type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
create or replace view public.submission_services_log as
with payments as (
select
session_id,
payment_id::text as event_id,
'Pay' as event_type,
initcap(status) as status,
'{}'::jsonb as response,
created_at
from payment_status
where status != 'created'
and created_at >= '2024-01-01'
), submissions as (
select
(seil.request -> 'payload' -> 'payload' ->> 'sessionId')::uuid as session_id,
se.id as event_id,
case
when se.webhook_conf::text like '%bops%' then 'Submit to BOPS'
when se.webhook_conf::text like '%uniform%' then 'Submit to Uniform'
when se.webhook_conf::text like '%email-submission%' then 'Send to email'
when se.webhook_conf::text like '%upload-submission%' then 'Upload to AWS S3'
else se.webhook_conf::text
end as event_type,
case
when seil.status = 200 then 'Success'
else format('Failed (%s)', seil.status)
end as status,
seil.response::jsonb,
seil.created_at
from hdb_catalog.hdb_scheduled_events se
left join hdb_catalog.hdb_scheduled_event_invocation_logs seil on seil.event_id = se.id
where se.webhook_conf::text not like '%email/%'
and seil.created_at >= '2024-01-01'
), all_events as (
select * from payments
union all
select * from submissions
)
SELECT
ls.flow_id,
ae.*
FROM all_events ae
left join public.lowcal_sessions ls on ls.id = ae.session_id
WHERE ls.flow_id is not null
order by ae.created_at desc;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
create or replace view public.submission_services_log as
with payments as (
select
ps.session_id,
ps.payment_id::text as event_id,
'Pay' as event_type,
initcap(ps.status) as status,
jsonb_build_object(
'status', ps.status,
'description', pse.comment,
'govuk_pay_reference', ps.payment_id::text
) as response,
ps.created_at,
false as retry
from payment_status ps
left join payment_status_enum pse on pse.value = ps.status
where ps.status != 'created'
and ps.created_at >= '2024-01-01'
), retries as (
select
id
from hdb_catalog.hdb_scheduled_event_invocation_logs
where (event_id, created_at) in (
select
seil.event_id,
max(seil.created_at)
from hdb_catalog.hdb_scheduled_event_invocation_logs seil
left join hdb_catalog.hdb_scheduled_events se on se.id = seil.event_id
where se.tries > 1
group by seil.event_id
)
), submissions as (
select
(seil.request -> 'payload' -> 'payload' ->> 'sessionId')::uuid as session_id,
se.id as event_id,
case
when se.webhook_conf::text like '%bops%' then 'Submit to BOPS'
when se.webhook_conf::text like '%uniform%' then 'Submit to Uniform'
when se.webhook_conf::text like '%email-submission%' then 'Send to email'
when se.webhook_conf::text like '%upload-submission%' then 'Upload to AWS S3'
else se.webhook_conf::text
end as event_type,
case
when seil.status = 200 then 'Success'
else format('Failed (%s)', seil.status)
end as status,
seil.response::jsonb,
seil.created_at,
exists(select 1 from retries r where r.id = seil.id) as retry
from hdb_catalog.hdb_scheduled_events se
left join hdb_catalog.hdb_scheduled_event_invocation_logs seil on seil.event_id = se.id
where se.webhook_conf::text not like '%email/%'
and seil.created_at >= '2024-01-01'
), all_events as (
select * from payments
union all
select * from submissions
)
SELECT
ls.flow_id,
ae.*
FROM all_events ae
left join public.lowcal_sessions ls on ls.id = ae.session_id
WHERE ls.flow_id is not null
order by ae.created_at desc;

0 comments on commit b925a59

Please sign in to comment.