import { WebSiteManagementModels } from '@azure/arm-appservice' ; import { isArray } from 'util' ; import { AzExtTreeItem , IActionContext } from 'vscode-azureextensionui' ; import { localize } from '../../localize' ; import { delay } from '../../utils/delay' ; import { FunctionsTreeItemBase } from '../FunctionsTreeItemBase' ; import { SlotTreeItemBase } from '../SlotTreeItemBase' ; import { getFunctionNameFromId , RemoteFunctionTreeItem } from './RemoteFunctionTreeItem' ; export class RemoteFunctionsTreeItem extends FunctionsTreeItemBase { public readonly parent : SlotTreeItemBase ; public isReadOnly : boolean ; private _nextLink : string | undefined ; private constructor ( parent ) { super ( parent ) ; } public static async createFunctionsTreeItem ( context , parent ) { const ti = new RemoteFunctionsTreeItem ( parent ) ; await ti . refreshImpl ( context ) ; return ti ; } public async refreshImpl ( context ) { this . isReadOnly = await this . parent . isReadOnly ( context ) ; } public hasMoreChildrenImpl ( ) { return ! ! this . _nextLink ; } public async loadMoreChildrenImpl ( clearCache , context ) { if ( clearCache ) { this . _nextLink = undefined ; } const client = await this . parent . site . createClient ( context ) ; let funcs ; const maxTime = Date . now ( ) + 2 * 60 * 1000 ; let attempt = 1 ; while ( true ) { funcs = this . _nextLink ? await client . listFunctionsNext ( this . _nextLink ) : await client . listFunctions ( ) ; if ( ! isArray ( funcs ) ) { throw new Error ( localize ( 'failedToList' , 'Failed to list functions.' ) ) ; } if ( Date . now ( ) > maxTime || ! ( funcs . length === 1 && isWarmupFunction ( funcs [ 0 ] ) ) ) { context . telemetry . measurements . listFunctionsAttempt = attempt ; break ; } else { attempt += 1 ; await delay ( 10 * 1000 ) ; } } this . _nextLink = funcs . nextLink ; return await this . createTreeItemsWithErrorHandling ( funcs , 'azFuncInvalidFunction' , async ( fe ) => await RemoteFunctionTreeItem . create ( context , this , fe ) , ( fe ) => { return fe . id ? getFunctionNameFromId ( fe . id ) : undefined ; } ) ; } } function isWarmupFunction ( func ) { try { return ! ! func . id && getFunctionNameFromId ( func . id ) . toLowerCase ( ) === 'warmup' ; } catch { return false ; } }