From 853611b69f51faa37eed11cff7b742c65de02fc7 Mon Sep 17 00:00:00 2001 From: wss-git Date: Mon, 27 Dec 2021 18:09:00 +0800 Subject: [PATCH] fix: invoke function add timeout --- src/index.ts | 16 +++++++++++++++- src/interface/entity.ts | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ec8c84f..c14c6ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export default class FcRemoteInvoke { async invoke(inputs: InputProps): Promise { const { props, + timeout, eventPayload, credentials, isHelp, @@ -31,7 +32,7 @@ export default class FcRemoteInvoke { let fcClient; if (!props.domainName) { const fcCommon = await core.loadComponent('devsapp/fc-common'); - fcClient = await fcCommon.makeFcClient({ ...inputs, props: { region: props.region }}); + fcClient = await fcCommon.makeFcClient({ ...inputs, props: { region: props.region, timeout }}); } const remoteInvoke = new RemoteInvoke(fcClient, credentials.AccountID); await remoteInvoke.invoke(props, eventPayload, { invocationType, statefulAsyncInvocationId }); @@ -51,6 +52,7 @@ export default class FcRemoteInvoke { const parsedArgs: {[key: string]: any} = core.commandParse({ ...inputs, args }, { boolean: ['help', 'event-stdin'], + number: ['timeout'], string: ['invocation-type', 'event', 'event-file', 'region', 'domain-name','service-name', 'function-name', 'qualifier', 'stateful-async-invocation-id'], alias: { 'help': 'h', @@ -108,8 +110,20 @@ export default class FcRemoteInvoke { throw new Error('region/serviceName(service-name)/functionName(function-name) can not be empty.'); } + // 超时时间获取的原理:https://github.com/devsapp/fc/issues/480 + const propsTimeout = argsData.timeout || inputs.props?.timeout; + let timeout = 600; + if (_.isNumber(propsTimeout)) { + if (_.isEmpty(inputs.props?.runtime) || inputs.props?.runtime === 'custom-container') { + timeout = propsTimeout + 7 * 60; + } else { + timeout = propsTimeout + 2 * 60; + } + } + return { props, + timeout, credentials: inputs.credentials, eventPayload, isHelp: false, diff --git a/src/interface/entity.ts b/src/interface/entity.ts index 9614ed6..4d9dd72 100644 --- a/src/interface/entity.ts +++ b/src/interface/entity.ts @@ -25,8 +25,10 @@ export interface IProperties { region: string; serviceName: string; functionName: string; + runtime?: string; qualifier?: string; domainName?: string; + timeout?: string; } export function isProperties(args: any): args is IProperties { if (!args) {