Skip to content

Commit 9d50c7f

Browse files
committed
minor change
1 parent cece758 commit 9d50c7f

File tree

1 file changed

+46
-61
lines changed

1 file changed

+46
-61
lines changed

src/lib/utils.ts

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -837,71 +837,56 @@ export async function listenToSmartUISSE(
837837
}
838838

839839
export async function startSSEListener(ctx: Context) {
840-
let retryCount = 0;
841-
const maxRetries = 3;
842840
let currentConnection: { abort: () => void } | null = null;
843841
let errorCount = 0;
844842

845-
const connectWithRetry = async () => {
846-
try {
847-
ctx.log.debug(`Attempting SSE connection (attempt ${retryCount + 1}/${maxRetries})`);
848-
const accessKey = ctx.env.LT_ACCESS_KEY;
849-
const username = ctx.env.LT_USERNAME;
850-
851-
const basicAuthToken = createBasicAuthToken(username, accessKey);
852-
ctx.log.debug(`Basic auth token: ${basicAuthToken}`);
853-
currentConnection = await listenToSmartUISSE(
854-
ctx.env.SMARTUI_SSE_URL,
855-
basicAuthToken,
856-
(eventType, data) => {
857-
switch (eventType) {
858-
case 'open':
859-
ctx.log.debug('Connected to SSE server');
860-
retryCount = 0;
861-
break;
862-
863-
case 'connection':
864-
ctx.log.debug('Connection confirmed:', data);
865-
retryCount = 0;
866-
break;
867-
868-
case 'Dot_buildCompleted':
869-
ctx.log.debug('Build completed');
870-
console.log('Build completed');
871-
currentConnection?.abort();
872-
if(errorCount > 0) {
873-
process.exit(1);
874-
}
875-
process.exit(0);
843+
try {
844+
ctx.log.debug('Attempting SSE connection');
845+
const accessKey = ctx.env.LT_ACCESS_KEY;
846+
const username = ctx.env.LT_USERNAME;
847+
848+
const basicAuthToken = createBasicAuthToken(username, accessKey);
849+
ctx.log.debug(`Basic auth token: ${basicAuthToken}`);
850+
currentConnection = await listenToSmartUISSE(
851+
ctx.env.SMARTUI_SSE_URL,
852+
basicAuthToken,
853+
(eventType, data) => {
854+
switch (eventType) {
855+
case 'open':
856+
ctx.log.debug('Connected to SSE server');
857+
break;
858+
859+
case 'connection':
860+
ctx.log.debug('Connection confirmed:', data);
861+
break;
862+
863+
case 'Dot_buildCompleted':
864+
ctx.log.debug('Build completed');
865+
console.log('Build completed');
866+
currentConnection?.abort();
867+
if(errorCount > 0) {
868+
process.exit(1);
869+
}
870+
process.exit(0);
871+
872+
case 'DOTUIError':
873+
if (data.buildId== ctx.build.id) {
874+
errorCount++;
875+
console.error('Error in build:', data.message);
876+
}
877+
break;
878+
879+
case 'error':
880+
ctx.log.debug('SSE Error occurred:', data);
881+
currentConnection?.abort();
882+
process.exit(0);
876883

877-
case 'DOTUIError':
878-
if (data.buildId== ctx.build.id) {
879-
errorCount++;
880-
console.error('Error in build:', data.message);
881-
}
882-
break;
883-
884-
case 'error':
885-
ctx.log.debug('SSE Error occurred:', data);
886-
currentConnection?.abort();
887-
process.exit(0);
888-
889-
}
890884
}
891-
);
892-
893-
} catch (error) {
894-
ctx.log.debug(`Failed to start SSE listener (attempt ${retryCount + 1}):`, error);
895-
retryCount++;
896-
897-
if (retryCount < maxRetries) {
898-
ctx.log.debug(`Retrying in 2 seconds...`);
899-
setTimeout(connectWithRetry, 2000);
900-
} else {
901-
ctx.log.debug('Max retries reached. SSE listener failed.');
902885
}
903-
}
904-
};
905-
906-
connectWithRetry();
886+
);
887+
888+
} catch (error) {
889+
ctx.log.debug('Failed to start SSE listener:', error);
890+
throw error;
891+
}
907892
}

0 commit comments

Comments
 (0)