Skip to content

Commit 0364097

Browse files
Merge pull request #43 from prisma/DC-4828-json-flag
DC-4828 `--json` flag
2 parents 4d9bb9d + e18cd95 commit 0364097

File tree

4 files changed

+202
-113
lines changed

4 files changed

+202
-113
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dist/
66
npm-debug.log*
77
yarn-debug.log*
88
yarn-error.log*
9+
.open-next/
910

1011
# TypeScript
1112
*.tsbuildinfo

claim-db-worker/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

create-db-worker/src/index.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,39 @@ export default {
7070
return new Response('Missing region or name in request body', { status: 400 });
7171
}
7272

73-
const payload = JSON.stringify({ region, name });
7473
const prismaResponse = await fetch('https://api.prisma.io/v1/projects', {
7574
method: 'POST',
7675
headers: {
7776
'Content-Type': 'application/json',
7877
Authorization: `Bearer ${env.INTEGRATION_TOKEN}`,
7978
},
80-
body: payload,
79+
body: JSON.stringify({
80+
region,
81+
name,
82+
}),
8183
});
8284

8385
const prismaText = await prismaResponse.text();
8486

85-
// Trigger delete workflow for the new project
86-
try {
87-
const response = JSON.parse(prismaText);
88-
const projectID = response.data ? response.data.id : response.id;
89-
await env.DELETE_DB_WORKFLOW.create({ params: { projectID } });
90-
env.CREATE_DB_DATASET.writeDataPoint({
91-
blobs: ['database_created'],
92-
indexes: ['create_db'],
93-
});
94-
} catch (e) {
95-
console.error('Error parsing prismaText or triggering workflow:', e);
96-
}
87+
const backgroundTasks = async () => {
88+
try {
89+
const response = JSON.parse(prismaText);
90+
const projectID = response.data ? response.data.id : response.id;
91+
92+
const workflowPromise = env.DELETE_DB_WORKFLOW.create({ params: { projectID } });
93+
94+
const analyticsPromise = env.CREATE_DB_DATASET.writeDataPoint({
95+
blobs: ['database_created'],
96+
indexes: ['create_db'],
97+
});
98+
99+
await Promise.all([workflowPromise, analyticsPromise]);
100+
} catch (e) {
101+
console.error('Error in background tasks:', e);
102+
}
103+
};
104+
105+
ctx.waitUntil(backgroundTasks());
97106

98107
return new Response(prismaText, {
99108
status: prismaResponse.status,

0 commit comments

Comments
 (0)