UNPKG

worker-parrot-party

Version:
71 lines 3.02 kB
/** * This interface represents the configuration of the PoolParty. * - task: The function to be executed by the parrots. * - partySize: The number of parrots to be used. * - basePath: Path to where the automatic generated scripts are stored. * - compiledFolderName: The name of the folder where the compiled scripts are stored. * - libraryDeclaration: Definition of libraries to import to the worker script. * - helpers: Definition of helper functions to be used in the worker script. * - resourceLimits: Worker threads resource limits. * - onSuccess: Callback to be executed when all the tasks are completed. * - onError: Callback to be executed when an error occurs. */ export interface PoolPartyConfig { task: Function; partySize: number; retryInterval?: number; basePath?: string; compiledFolderName?: string; libraryDeclaration?: Array<{ name: string; importDeclaration: string; }>; helpers?: Array<Function>; resourceLimits?: { maxOldGenerationSizeMb: number; maxYoungGenerationSizeMb: number; codeRangeSizeMb: number; stackSizeMb: number; }; onSuccess(result: unknown): unknown; onError(error: unknown): unknown; } export declare class PoolParty { private readonly _poolPartyConfig; private readonly _logger; private readonly _parrotIdleQueue; private _executionScriptFilePath; constructor(_poolPartyConfig: PoolPartyConfig); private _compileExecutionScripts; /** * Function that sapwns the worker parrots based on the configuration size provided. * @param executionFilePath Path to the execution script */ spawnParrots(): Promise<void>; /** * Function thta returns an idle parrot, if there is no idle, throws a NoIdleParrotError. * @returns {Parrot} */ private _getIdleParrot; /** * Function that Handles Parrot errors and makes sure to spawn a new parrot if the error is not a NoIdleParrotError. * Additionally, kills the parrot instance that caused the error. * * @param parrot Worker parrot instance that throwed the error * @param parrotError Error that was thrown by the parrot */ private _handleParrotError; /** * * @param args Arguments to be passed to the task function * @returns A Promise that resolves to the result of the task function. Additionally calls the onSuccess function * if provided. If there is an error during the task function execution, calls the onError function if provided. * * Finally, if there are no idle parrots, the task is added to the retry queue and waits until there is an idle parrot. * * Furthermore, when an error occurs and if the error is not identified as a NoIdleParrotError, the onError function is * called, and we spawn a new parrot, since the error causes the parrot to be unavailable for new tasks. */ run(args: Array<unknown>): Promise<Object>; } //# sourceMappingURL=PoolParty.d.ts.map