Skip to content

Commit

Permalink
feat: create parallel BOPS send events for v1 & v2 on all environments (
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Jan 9, 2024
1 parent 8b41972 commit 9763e76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
19 changes: 12 additions & 7 deletions api.planx.uk/modules/send/bops/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,16 @@ const sendToBOPSV2 = async (
.catch((error) => {
if (error.response) {
throw new Error(
`Sending to BOPS v2 failed (${localAuthority}):\n${JSON.stringify(
error.response.data,
null,
2,
)}`,
`Sending to BOPS v2 failed (${[localAuthority, payload?.sessionId]
.filter(Boolean)
.join(" - ")}):\n${JSON.stringify(error.response.data, null, 2)}`,
);
} else {
// re-throw other errors
throw new Error(
`Sending to BOPS v2 failed (${localAuthority}):\n${error}`,
`Sending to BOPS v2 failed (${[localAuthority, payload?.sessionId]
.filter(Boolean)
.join(" - ")}):\n${error}`,
);
}
});
Expand All @@ -279,7 +279,12 @@ const sendToBOPSV2 = async (
next(
new ServerError({
status: 500,
message: `Sending to BOPS v2 failed (${localAuthority})`,
message: `Sending to BOPS v2 failed (${[
localAuthority,
payload?.sessionId,
]
.filter(Boolean)
.join(" - ")})`,
cause: err,
}),
);
Expand Down
21 changes: 9 additions & 12 deletions api.planx.uk/modules/send/createSendEvents/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,25 @@ const createSendEvents: CreateSendEventsController = async (
if (bops) {
const bopsEvent = await createScheduledEvent({
webhook: `{{HASURA_PLANX_API_URL}}/bops/${bops.localAuthority}`,
schedule_at: new Date(now.getTime() + 30 * 1000),
schedule_at: new Date(now.getTime() + 25 * 1000),
payload: bops.body,
comment: `bops_submission_${sessionId}`,
});
combinedResponse["bops"] = bopsEvent;

const isProduction = process.env.APP_ENVIRONMENT === "production";
if (!isProduction) {
const bopsV2Event = await createScheduledEvent({
webhook: `{{HASURA_PLANX_API_URL}}/bops-v2/${bops.localAuthority}`,
schedule_at: new Date(now.getTime() + 45 * 1000),
payload: bops.body,
comment: `bops_v2_submission_${sessionId}`,
});
combinedResponse["bops_v2"] = bopsV2Event;
}
const bopsV2Event = await createScheduledEvent({
webhook: `{{HASURA_PLANX_API_URL}}/bops-v2/${bops.localAuthority}`,
schedule_at: new Date(now.getTime() + 50 * 1000),
payload: bops.body,
comment: `bops_v2_submission_${sessionId}`,
});
combinedResponse["bops_v2"] = bopsV2Event;
}

if (uniform) {
const uniformEvent = await createScheduledEvent({
webhook: `{{HASURA_PLANX_API_URL}}/uniform/${uniform.localAuthority}`,
schedule_at: new Date(now.getTime() + 60 * 1000),
schedule_at: new Date(now.getTime() + 75 * 1000),
payload: uniform.body,
comment: `uniform_submission_${sessionId}`,
});
Expand Down

0 comments on commit 9763e76

Please sign in to comment.