@@ -58,6 +58,21 @@ const mockServer = {
5858 } ,
5959} ;
6060
61+ async function streamLogChunks ( req , res ) {
62+ // Asynchronously write each chunk to the response stream
63+ for ( const chunk of MOCKED_ACTOR_LOGS ) {
64+ res . write ( chunk ) ;
65+ res . flush ( ) ; // Flush the buffer and send the chunk immediately
66+ // Wait for a short period to simulate work being done on the server
67+ await new Promise ( ( resolve ) => {
68+ setTimeout ( resolve , 10 ) ;
69+ } ) ;
70+ }
71+
72+ // End the response stream once all chunks have been sent
73+ res . end ( ) ;
74+ }
75+
6176// Debugging middleware
6277app . use ( ( req , res , next ) => {
6378 next ( ) ;
@@ -83,40 +98,14 @@ v2Router.use('/acts/redirect-actor-id', async (req, res) => {
8398} ) ;
8499v2Router . use ( '/acts' , actorRouter ) ;
85100v2Router . use ( '/actor-builds' , buildRouter ) ;
86- v2Router . use ( '/actor-runs/redirect-run-id/log' , async ( req , res ) => {
87- // Asynchronously write each chunk to the response stream
88- for ( const chunk of MOCKED_ACTOR_LOGS ) {
89- res . write ( chunk ) ;
90- res . flush ( ) ; // Flush the buffer and send the chunk immediately
91- // Wait for a short period to simulate work being done on the server
92- await new Promise ( ( resolve ) => {
93- setTimeout ( resolve , 10 ) ;
94- } ) ;
95- }
96-
97- // End the response stream once all chunks have been sent
98- res . end ( ) ;
99- } ) ;
101+ v2Router . use ( '/actor-runs/redirect-run-id/log' , streamLogChunks ) ;
100102v2Router . use ( '/actor-runs/redirect-run-id' , async ( req , res ) => {
101103 res . json ( { data : { id : 'redirect-run-id' , actId : 'redirect-actor-id' , status : 'SUCCEEDED' } } ) ;
102104} ) ;
103105v2Router . use ( '/actor-runs' , runRouter ) ;
104106v2Router . use ( '/actor-tasks' , taskRouter ) ;
105107v2Router . use ( '/users' , userRouter ) ;
106- v2Router . use ( '/logs/redirect-log-id' , async ( req , res ) => {
107- // Asynchronously write each chunk to the response stream
108- for ( const chunk of MOCKED_ACTOR_LOGS ) {
109- res . write ( chunk ) ;
110- res . flush ( ) ; // Flush the buffer and send the chunk immediately
111- // Wait for a short period to simulate work being done on the server
112- await new Promise ( ( resolve ) => {
113- setTimeout ( resolve , 10 ) ;
114- } ) ;
115- }
116-
117- // End the response stream once all chunks have been sent
118- res . end ( ) ;
119- } ) ;
108+ v2Router . use ( '/logs/redirect-log-id' , streamLogChunks ) ;
120109v2Router . use ( '/logs' , logRouter ) ;
121110v2Router . use ( '/datasets' , datasetRouter ) ;
122111v2Router . use ( '/key-value-stores' , keyValueStores ) ;
0 commit comments