import cp from 'child_process' ; import { syncPRInfoForBranches } from '../../lib/sync/pr_info' ; import Branch from '../../wrapper-classes/branch' ; import { repoConfig } from '../config' ; export function refreshPRInfoInBackground ( ) { if ( ! repoConfig . graphiteInitialized ( ) ) { return ; } const now = Date . now ( ) ; const lastFetchedMs = repoConfig . getLastFetchedPRInfoMs ( ) ; const msInSecond = 1000 ; if ( lastFetchedMs === undefined || now - lastFetchedMs > 60 * msInSecond ) { repoConfig . setLastFetchedPRInfoMs ( now ) ; cp . spawn ( '/usr/bin/env' , [ 'node' , __filename ] , { detached : true , stdio : 'ignore' , } ) ; } } async function refreshPRInfo ( ) { try { const branchesWithPRInfo = Branch . allBranches ( ) . filter ( ( branch ) => branch . getPRInfo ( ) !== undefined ) ; await syncPRInfoForBranches ( branchesWithPRInfo ) ; } catch ( err ) { return ; } } if ( process . argv [ 1 ] === __filename ) { void refreshPRInfo ( ) ; }