Merge pull request #16 from devsapp/support-stateful-async-invocation-id

feat: add --stateful-async-invocation-id args
This commit is contained in:
wss-git 2021-11-16 13:29:42 +08:00 committed by GitHub
commit 978e57fef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -19,6 +19,7 @@ export default class FcRemoteInvoke {
credentials,
isHelp,
invocationType,
statefulAsyncInvocationId,
} = await this.handlerInputs(inputs);
await this.report('fc-remote-invoke', 'invoke', credentials?.AccountID);
@ -33,7 +34,7 @@ export default class FcRemoteInvoke {
fcClient = await fcCommon.makeFcClient({ ...inputs, props: { region: props.region }});
}
const remoteInvoke = new RemoteInvoke(fcClient, credentials.AccountID);
await remoteInvoke.invoke(props, eventPayload, { invocationType });
await remoteInvoke.invoke(props, eventPayload, { invocationType, statefulAsyncInvocationId });
}
private async report(componentName: string, command: string, accountID: string): Promise<void> {
@ -50,7 +51,7 @@ export default class FcRemoteInvoke {
const parsedArgs: {[key: string]: any} = core.commandParse({ ...inputs, args }, {
boolean: ['help', 'event-stdin'],
string: ['invocation-type', 'event', 'event-file', 'region', 'domain-name','service-name', 'function-name', 'qualifier'],
string: ['invocation-type', 'event', 'event-file', 'region', 'domain-name','service-name', 'function-name', 'qualifier', 'stateful-async-invocation-id'],
alias: {
'help': 'h',
'event': 'e',
@ -73,6 +74,7 @@ export default class FcRemoteInvoke {
'event-stdin': eventStdin,
'invocation-type': invocationType = 'sync',
'domain-name': domainName,
'stateful-async-invocation-id': statefulAsyncInvocationId,
} = argsData;
const eventPayload = { event, eventFile, eventStdin };
// @ts-ignore: 判断三个值有几个真
@ -111,6 +113,7 @@ export default class FcRemoteInvoke {
eventPayload,
isHelp: false,
invocationType: _.upperFirst(invocationType),
statefulAsyncInvocationId,
};
}

View File

@ -13,7 +13,7 @@ export default class RemoteInvoke {
this.accountId = accountId;
}
async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType }) {
async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType, statefulAsyncInvocationId }) {
const event = await Event.eventPriority(eventPayload);
logger.debug(`event: ${event}`);
@ -32,12 +32,13 @@ export default class RemoteInvoke {
const payload: any = { event, serviceName, functionName, qualifier };
if (_.isEmpty(httpTriggers)) {
payload.invocationType = invocationType;
payload.statefulAsyncInvocationId = statefulAsyncInvocationId;
payload.event = event;
await this.eventInvoke(payload);
} else {
payload.region = region;
payload.event = this.getJsonEvent(event);
await this.httpInvoke(payload);
}
}
@ -48,9 +49,9 @@ export default class RemoteInvoke {
payload.headers = {};
}
payload.headers['X-Fc-Log-Type'] = 'Tail';
const { body, headers } = await got(url, payload);
this.showLog(headers['x-fc-log-result']);
logger.log('\nFC Invoke Result:', 'green');
console.log(body);
@ -74,13 +75,14 @@ export default class RemoteInvoke {
functionName,
event,
qualifier = 'LATEST',
invocationType
invocationType,
statefulAsyncInvocationId
}) {
if (invocationType === 'Sync') {
const rs = await this.fcClient.invokeFunction(serviceName, functionName, event, {
'X-Fc-Log-Type': 'Tail',
'X-Fc-Invocation-Type': invocationType
'X-Fc-Invocation-Type': invocationType,
}, qualifier);
this.showLog(rs.headers['x-fc-log-result']);
@ -88,8 +90,10 @@ export default class RemoteInvoke {
console.log(rs.data);
console.log('\n');
} else {
logger.debug(`Stateful async invocation id: ${statefulAsyncInvocationId}`);
const { headers } = await this.fcClient.invokeFunction(serviceName, functionName, event, {
'X-Fc-Invocation-Type': invocationType
'X-Fc-Invocation-Type': invocationType,
'X-Fc-Stateful-Async-Invocation-Id': statefulAsyncInvocationId,
}, qualifier);
const rId = headers['x-fc-request-id'];
@ -177,4 +181,4 @@ export default class RemoteInvoke {
throw new Error('handler event error. Example: https://github.com/devsapp/fc-remote-invoke/blob/master/example/http.json');
}
}
}
}