Skip to content

Commit b53dc57

Browse files
authored
[feature][scf新增api] (#264)
toolkit组件新增GetRequestStatus API
1 parent d416106 commit b53dc57

File tree

4 files changed

+101
-7
lines changed

4 files changed

+101
-7
lines changed

__tests__/scf/base.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,27 @@ describe('Scf', () => {
519519
expect(outputs.Triggers).toEqual([]);
520520
});
521521

522+
test('get request status', async () => {
523+
const invokeRes = await scf.invoke({
524+
namespace: inputs.namespace,
525+
functionName: inputs.name,
526+
});
527+
528+
console.log(invokeRes);
529+
530+
const inputParams = {
531+
functionName: inputs.name,
532+
functionRequestId: invokeRes.Result.FunctionRequestId,
533+
namespace: inputs.namespace,
534+
// startTime: "2022-01-06 20:00:00",
535+
// endTime: "2022-12-16 20:00:00"
536+
};
537+
538+
const res = await scf.scf.getRequestStatus(inputParams);
539+
console.log(res);
540+
expect(res.TotalCount).toEqual(1);
541+
});
542+
522543
test('remove', async () => {
523544
const res = await scf.remove({
524545
functionName: inputs.name,

src/modules/scf/apis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ACTIONS = [
2626
'DeleteProvisionedConcurrencyConfig',
2727
'GetReservedConcurrencyConfig',
2828
'GetProvisionedConcurrencyConfig',
29+
'GetRequestStatus'
2930
] as const;
3031

3132
export type ActionType = typeof ACTIONS[number];

src/modules/scf/entities/scf.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { Capi } from '@tencent-sdk/capi';
2-
import { sleep, waitResponse } from '@ygkit/request';
1+
import {Capi} from '@tencent-sdk/capi';
2+
import {sleep, waitResponse} from '@ygkit/request';
33
import dayjs from 'dayjs';
4-
import { ApiTypeError, ApiError } from '../../../utils/error';
5-
import { formatDate } from '../../../utils/dayjs';
4+
import {ApiError, ApiTypeError} from '../../../utils/error';
5+
import {formatDate} from '../../../utils/dayjs';
66
import CONFIGS from '../config';
77
import Cls from '../../cls';
8-
import { formatInputs } from '../utils';
8+
import {formatInputs} from '../utils';
99

1010
import BaseEntity from './base';
1111

1212
import {
13-
ScfCreateFunctionInputs,
14-
FunctionInfo,
1513
FaasBaseConfig,
14+
FunctionInfo,
1615
GetLogOptions,
16+
GetRequestStatusOptions,
17+
ScfCreateFunctionInputs,
1718
UpdateFunctionCodeOptions,
1819
} from '../interface';
1920

@@ -442,4 +443,35 @@ export default class ScfEntity extends BaseEntity {
442443
return undefined;
443444
}
444445
}
446+
447+
// 获取函数单个请求运行状态
448+
async getRequestStatus(inputs: GetRequestStatusOptions) {
449+
const reqParams: {
450+
Namespace?: string;
451+
FunctionName?: string;
452+
FunctionRequestId?: string;
453+
StartTime?: string;
454+
EndTime?: string;
455+
} = {
456+
Namespace: inputs.namespace || 'default',
457+
FunctionName: inputs.functionName,
458+
FunctionRequestId: inputs.functionRequestId,
459+
};
460+
461+
if (inputs.startTime) {
462+
reqParams.StartTime = inputs.startTime
463+
}
464+
465+
if (inputs.endTime) {
466+
reqParams.EndTime = inputs.endTime
467+
}
468+
469+
const reqInputs: Partial<typeof reqParams> = reqParams;
470+
471+
try {
472+
return await this.request({Action: 'GetRequestStatus', ...reqInputs});
473+
} catch (e) {
474+
console.log(e);
475+
}
476+
}
445477
}

src/modules/scf/interface.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,43 @@ export interface UpdateFunctionCodeOptions {
367367
// image 方式
368368
Code?: FunctionCode;
369369
}
370+
371+
export interface GetRequestStatusOptions {
372+
// 函数名称
373+
functionName: string;
374+
// 请求 ID
375+
functionRequestId: string;
376+
// 命名空间
377+
namespace?: string;
378+
// 开始时间
379+
startTime?: string;
380+
// 结束时间
381+
endTime?: string;
382+
}
383+
384+
export interface GetRequestStatusOptions {
385+
/**
386+
* 函数名称
387+
*/
388+
functionName: string
389+
390+
/**
391+
* 需要查询状态的请求 id
392+
*/
393+
functionRequestId: string
394+
395+
/**
396+
* 函数的所在的命名空间
397+
*/
398+
namespace?: string
399+
400+
/**
401+
* 查询的开始时间,例如:2017-05-16 20:00:00,不填默认为当前时间 - 15min
402+
*/
403+
startTime?: string
404+
405+
/**
406+
* 查询的结束时间,例如:2017-05-16 20:59:59,不填默认为当前时间。EndTime 需要晚于 StartTime。
407+
*/
408+
endTime?: string
409+
}

0 commit comments

Comments
 (0)