feat: add --stateful-async-invocation-id args

This commit is contained in:
千风 2021-10-19 21:14:49 +08:00
parent f7670a02aa
commit 9c10415e0f
2 changed files with 17 additions and 10 deletions

View File

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

View File

@ -13,7 +13,7 @@ export default class RemoteInvoke {
this.accountId = accountId; this.accountId = accountId;
} }
async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType }) { async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType, statefulAsyncInvocationId }) {
const event = await Event.eventPriority(eventPayload); const event = await Event.eventPriority(eventPayload);
logger.debug(`event: ${event}`); logger.debug(`event: ${event}`);
@ -32,6 +32,7 @@ export default class RemoteInvoke {
const payload: any = { event, serviceName, functionName, qualifier }; const payload: any = { event, serviceName, functionName, qualifier };
if (_.isEmpty(httpTriggers)) { if (_.isEmpty(httpTriggers)) {
payload.invocationType = invocationType; payload.invocationType = invocationType;
payload.statefulAsyncInvocationId = statefulAsyncInvocationId;
payload.event = event; payload.event = event;
await this.eventInvoke(payload); await this.eventInvoke(payload);
} else { } else {
@ -74,13 +75,14 @@ export default class RemoteInvoke {
functionName, functionName,
event, event,
qualifier = 'LATEST', qualifier = 'LATEST',
invocationType invocationType,
statefulAsyncInvocationId
}) { }) {
if (invocationType === 'Sync') { if (invocationType === 'Sync') {
const rs = await this.fcClient.invokeFunction(serviceName, functionName, event, { const rs = await this.fcClient.invokeFunction(serviceName, functionName, event, {
'X-Fc-Log-Type': 'Tail', 'X-Fc-Log-Type': 'Tail',
'X-Fc-Invocation-Type': invocationType 'X-Fc-Invocation-Type': invocationType,
}, qualifier); }, qualifier);
this.showLog(rs.headers['x-fc-log-result']); this.showLog(rs.headers['x-fc-log-result']);
@ -88,8 +90,10 @@ export default class RemoteInvoke {
console.log(rs.data); console.log(rs.data);
console.log('\n'); console.log('\n');
} else { } else {
logger.debug(`Stateful async invocation id: ${statefulAsyncInvocationId}`);
const { headers } = await this.fcClient.invokeFunction(serviceName, functionName, event, { 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); }, qualifier);
const rId = headers['x-fc-request-id']; const rId = headers['x-fc-request-id'];