UNPKG

3.05 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as childProcess from "child_process";
3import { Message, PromiseResponseMessage } from "./provider";
4import { AsyncIterableQueue } from "./throttle";
5import { AnyFunction } from "./types";
6export declare const isGenerator: (fn: Function) => boolean;
7export declare const filename: string;
8export interface CallId {
9 callId: string;
10}
11export interface Trampoline {
12 trampoline: AnyFunction;
13}
14export interface TrampolineFactory {
15 filename: string;
16 makeTrampoline: (wrapper: Wrapper) => Trampoline;
17}
18export interface FunctionCall extends CallId {
19 args: string;
20 modulePath: string;
21 name: string;
22 ResponseQueueId: string;
23}
24export interface CallingContext {
25 call: FunctionCall;
26 startTime: number;
27 logUrl?: string;
28 executionId?: string;
29 instanceId?: string;
30}
31export interface ModuleType {
32 [name: string]: any;
33}
34export declare function createErrorResponse(err: any, { call, startTime, logUrl, executionId }: CallingContext): PromiseResponseMessage;
35export interface WrapperOptions {
36 /**
37 * Logging function for console.log/warn/error output. Only available in
38 * child process mode. This is mainly useful for debugging the "local"
39 * mode which runs code locally. In real clouds the logs will end up in the
40 * cloud logging service (e.g. Cloudwatch Logs, or Google Stackdriver logs).
41 * Defaults to console.log.
42 */
43 wrapperLog?: (msg: string) => void;
44 childProcess?: boolean;
45 childProcessMemoryLimitMb?: number;
46 childProcessTimeoutMs?: number;
47 childProcessEnvironment?: {
48 [key: string]: string;
49 };
50 childDir?: string;
51 wrapperVerbose?: boolean;
52 validateSerialization?: boolean;
53}
54export declare const WrapperOptionDefaults: Required<WrapperOptions>;
55declare type ErrorCallback = (err: Error) => Error;
56declare type MessageCallback = (msg: Message) => Promise<void>;
57export interface WrapperExecuteOptions {
58 errorCallback?: ErrorCallback;
59 onMessage: MessageCallback;
60 measureCpuUsage?: boolean;
61}
62export declare class Wrapper {
63 executing: boolean;
64 protected verbose: boolean;
65 protected funcs: ModuleType;
66 protected child?: childProcess.ChildProcess;
67 protected childPid?: number;
68 protected log: (msg: string) => void;
69 protected queue: AsyncIterableQueue<Message>;
70 readonly options: Required<WrapperOptions>;
71 protected monitoringTimer?: NodeJS.Timer;
72 constructor(fModule: ModuleType, options?: WrapperOptions);
73 protected lookupFunction(request: object): AnyFunction;
74 protected stopCpuMonitoring(): void;
75 protected startCpuMonitoring(pid: number, callId: string): void;
76 stop(): void;
77 execute(callingContext: CallingContext, { errorCallback, onMessage, measureCpuUsage }: WrapperExecuteOptions): Promise<void>;
78 protected logLines: (msg: string) => void;
79 protected setupChildProcess(): childProcess.ChildProcess;
80}
81export interface CpuMeasurement {
82 stime: number;
83 utime: number;
84 elapsed: number;
85}
86export {};