faastjs
Version:
Serverless batch computing made simple.
89 lines (88 loc) • 3.06 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import childProcess from "child_process";
import { Message, PromiseResponseMessage } from "./provider";
import { AsyncIterableQueue } from "./throttle";
import { AnyFunction } from "./types";
export declare const isGenerator: (fn: Function) => boolean;
export declare const filename: string;
export interface CallId {
callId: string;
}
export interface Trampoline {
trampoline: AnyFunction;
}
export interface TrampolineFactory {
filename: string;
makeTrampoline: (wrapper: Wrapper) => Trampoline;
}
export interface FunctionCall extends CallId {
args: string;
modulePath: string;
name: string;
ResponseQueueId: string;
}
export interface CallingContext {
call: FunctionCall;
startTime: number;
logUrl?: string;
executionId?: string;
instanceId?: string;
}
export interface ModuleType {
[name: string]: any;
}
export declare function createErrorResponse(err: any, { call, startTime, logUrl, executionId }: CallingContext): PromiseResponseMessage;
export interface WrapperOptions {
/**
* Logging function for console.log/warn/error output. Only available in
* child process mode. This is mainly useful for debugging the "local"
* mode which runs code locally. In real clouds the logs will end up in the
* cloud logging service (e.g. Cloudwatch Logs).
* Defaults to console.log.
*/
wrapperLog?: (msg: string) => void;
childProcess?: boolean;
childProcessMemoryLimitMb?: number;
childProcessTimeoutMs?: number;
childProcessEnvironment?: {
[key: string]: string;
};
childDir?: string;
wrapperVerbose?: boolean;
validateSerialization?: boolean;
}
export declare const WrapperOptionDefaults: Required<WrapperOptions>;
type ErrorCallback = (err: Error) => Error;
type MessageCallback = (msg: Message) => Promise<void>;
export interface WrapperExecuteOptions {
errorCallback?: ErrorCallback;
onMessage: MessageCallback;
measureCpuUsage?: boolean;
}
export declare class Wrapper {
executing: boolean;
selected: boolean;
protected verbose: boolean;
protected funcs: ModuleType;
protected child?: childProcess.ChildProcess;
protected childPid?: number;
protected log: (msg: string) => void;
protected queue: AsyncIterableQueue<Message>;
readonly options: Required<WrapperOptions>;
protected monitoringTimer?: NodeJS.Timer;
constructor(fModule: ModuleType, options?: WrapperOptions);
protected lookupFunction(request: object): AnyFunction;
protected stopCpuMonitoring(): void;
protected startCpuMonitoring(pid: number, callId: string): void;
stop(): void;
execute(callingContext: CallingContext, { errorCallback, onMessage, measureCpuUsage }: WrapperExecuteOptions): Promise<void>;
protected logLines: (msg: string) => void;
protected setupChildProcess(): childProcess.ChildProcess;
}
export interface CpuMeasurement {
stime: number;
utime: number;
elapsed: number;
}
export {};