@@ -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