@@ -3,8 +3,17 @@ import { Context } from '../types.js'
33import { chromium , firefox , webkit , Browser } from '@playwright/test'
44import constants from './constants.js' ;
55import chalk from 'chalk' ;
6+ import axios from 'axios' ;
7+
8+ import { globalAgent } from 'http' ;
9+ import { promisify } from 'util'
10+ const sleep = promisify ( setTimeout ) ;
611
712let isPollingActive = false ;
13+ let globalContext : Context ;
14+ export const setGlobalContext = ( newContext : Context ) : void => {
15+ globalContext = newContext ;
16+ } ;
817
918export function delDir ( dir : string ) : void {
1019 if ( fs . existsSync ( dir ) ) {
@@ -207,7 +216,7 @@ export function getRenderViewportsForOptions(options: any): Array<Record<string,
207216}
208217
209218// Global SIGINT handler
210- process . on ( 'SIGINT' , ( ) => {
219+ process . on ( 'SIGINT' , async ( ) => {
211220 if ( isPollingActive ) {
212221 console . log ( 'Fetching results interrupted. Exiting...' ) ;
213222 isPollingActive = false ;
@@ -218,7 +227,7 @@ process.on('SIGINT', () => {
218227} ) ;
219228
220229// Background polling function
221- export async function startPolling ( ctx : Context , task : any ) : Promise < void > {
230+ export async function startPolling ( ctx : Context ) : Promise < void > {
222231 ctx . log . info ( 'Fetching results in progress....' ) ;
223232 isPollingActive = true ;
224233
@@ -294,4 +303,25 @@ export async function startPolling(ctx: Context, task: any): Promise<void> {
294303 isPollingActive = false ;
295304 }
296305 } , 5000 ) ;
297- }
306+ }
307+
308+ export async function startPingPolling ( ctx : Context ) : Promise < void > {
309+ try {
310+ ctx . log . debug ( 'Sending initial ping to server...' ) ;
311+ await ctx . client . ping ( ctx . build . id , ctx . log ) ;
312+ ctx . log . debug ( 'Initial ping sent successfully.' ) ;
313+ } catch ( error : any ) {
314+ ctx . log . error ( `Error during initial ping: ${ error . message } ` ) ;
315+ }
316+
317+ setInterval ( async ( ) => {
318+ try {
319+ ctx . log . debug ( 'Sending ping to server...' ) ;
320+ await ctx . client . ping ( ctx . build . id , ctx . log ) ;
321+ ctx . log . debug ( 'Ping sent successfully.' ) ;
322+ } catch ( error : any ) {
323+ ctx . log . error ( `Error during ping polling: ${ error . message } ` ) ;
324+ }
325+ } , 10 * 60 * 1000 ) ;
326+ }
327+
0 commit comments