Skip to content

Commit b2322fe

Browse files
高魏洪claude
andcommitted
feat: add --skip-acceleration-wait flag to skip image acceleration polling after deploy
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 4ca1c1b commit b2322fe

5 files changed

Lines changed: 53 additions & 5 deletions

File tree

__tests__/ut/commands/deploy/impl/function_test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe('Service', () => {
8686

8787
expect(service.type).toBeUndefined();
8888
expect(service.skipPush).toBeUndefined();
89+
expect(service.skipAccelerationWait).toBeUndefined();
8990
expect(service.local).toEqual({
9091
functionName: 'test-function',
9192
runtime: 'nodejs12',
@@ -237,10 +238,40 @@ describe('Service', () => {
237238
{
238239
slsAuto: false,
239240
type: 'config',
241+
skipAccelerationWait: undefined,
240242
},
241243
);
242244
});
243245

246+
it('should pass skipAccelerationWait to deployFunction', async () => {
247+
service = new Service(mockInputs, { ...mockOpts, skipAccelerationWait: true });
248+
service.needDeploy = true;
249+
Object.defineProperty(service, 'type', {
250+
value: 'config',
251+
writable: true,
252+
});
253+
254+
const mockFcSdk = {
255+
deployFunction: jest.fn().mockResolvedValue(undefined),
256+
};
257+
Object.defineProperty(service, 'fcSdk', {
258+
value: mockFcSdk,
259+
writable: true,
260+
});
261+
262+
jest.spyOn(service as any, '_deployAuto').mockResolvedValue(undefined);
263+
jest.spyOn(service as any, '_uploadCode').mockResolvedValue(true);
264+
265+
await service.run();
266+
267+
expect(service.fcSdk.deployFunction).toHaveBeenCalledWith(
268+
expect.anything(),
269+
expect.objectContaining({
270+
skipAccelerationWait: true,
271+
}),
272+
);
273+
});
274+
244275
it('should upload code when type is not config', async () => {
245276
service = new Service(mockInputs, mockOpts);
246277
service.needDeploy = true;
@@ -308,6 +339,7 @@ describe('Service', () => {
308339
{
309340
slsAuto: false,
310341
type: 'code',
342+
skipAccelerationWait: undefined,
311343
},
312344
);
313345
});

src/commands-help/deploy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Examples:
1313
option: [
1414
['-y, --assume-yes', "[Optional] Don't ask, delete directly"],
1515
['--skip-push', '[Optional] Specify if skip automatically pushing docker container images'],
16+
[
17+
'--skip-acceleration-wait',
18+
'[Optional] Specify if skip waiting for image acceleration after deploy',
19+
],
1620
[
1721
"--function ['code'/'config']",
1822
"[Optional] Only deploy function configuration or code. Use 'code' to deploy function code only, use 'config' to deploy function configuration only",

src/resources/fc/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class FC extends FC_Client {
8181
static isCustomRuntime = isCustomRuntime;
8282
static replaceFunctionConfig = replaceFunctionConfig;
8383

84-
async untilFunctionStateOK(config: IFunction, reason: string) {
84+
async untilFunctionStateOK(config: IFunction, reason: string, skipAccelerationWait?: boolean) {
8585
const retryInterval = 2;
8686
const startTime = new Date().getTime();
8787
const calculateRetryTime = (minute: number) =>
@@ -93,6 +93,12 @@ export default class FC extends FC_Client {
9393
const retryContainerAccelerated = FC.isCustomContainerRuntime(config.runtime);
9494
// 部署镜像需要重试 3min, 直到达到!(State == Pending || LastUpdateStatus == InProgress)
9595
if (retryContainerAccelerated) {
96+
if (skipAccelerationWait) {
97+
logger.info(
98+
`Skip waiting for ${config.customContainerConfig.image} optimization. The function will be available for invocation once the image acceleration process is complete.`,
99+
);
100+
return;
101+
}
96102
console.log('');
97103
if (reason === 'CREATE') {
98104
if (isAppCenter()) {
@@ -183,7 +189,7 @@ export default class FC extends FC_Client {
183189
/**
184190
* 创建或者修改函数
185191
*/
186-
async deployFunction(config: IFunction, { slsAuto, type }): Promise<void> {
192+
async deployFunction(config: IFunction, { slsAuto, type, skipAccelerationWait }): Promise<void> {
187193
logger.debug(`Deploy function use config:\n${JSON.stringify(config, null, 2)}`);
188194
let needUpdate = false;
189195
let remoteConfig = null;
@@ -217,7 +223,7 @@ export default class FC extends FC_Client {
217223
logger.debug(`Need create function ${config.functionName}`);
218224
try {
219225
await this.createFunction(config);
220-
await this.untilFunctionStateOK(config, 'CREATE');
226+
await this.untilFunctionStateOK(config, 'CREATE', skipAccelerationWait);
221227
return;
222228
} catch (ex) {
223229
logger.debug(`Create function error: ${ex.message}`);
@@ -291,7 +297,7 @@ export default class FC extends FC_Client {
291297
_.unset(config, 'customContainerConfig');
292298
}
293299
await this.updateFunction(config);
294-
await this.untilFunctionStateOK(config, 'UPDATE');
300+
await this.untilFunctionStateOK(config, 'UPDATE', skipAccelerationWait);
295301
if (config.resourceGroupId) {
296302
const remoteResourceGroupId = remoteConfig?.body?.resourceGroupId;
297303
if (remoteResourceGroupId !== config.resourceGroupId) {

src/subCommands/deploy/impl/function.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ interface IOpts {
3333
type?: IType;
3434
yes?: boolean;
3535
skipPush?: boolean;
36+
skipAccelerationWait?: boolean;
3637
}
3738

3839
export default class Service extends Base {
3940
readonly type?: IType;
4041
readonly skipPush?: boolean = false;
42+
readonly skipAccelerationWait?: boolean = false;
4143

4244
remote?: any;
4345
local: IFunction;
@@ -54,6 +56,7 @@ export default class Service extends Base {
5456

5557
this.type = opts.type;
5658
this.skipPush = opts.skipPush;
59+
this.skipAccelerationWait = opts.skipAccelerationWait;
5760
logger.debug(`deploy function type: ${this.type}`);
5861

5962
this.local = _.cloneDeep(inputs.props);
@@ -131,6 +134,7 @@ export default class Service extends Base {
131134
await this.fcSdk.deployFunction(config, {
132135
slsAuto: !_.isEmpty(this.createResource.sls),
133136
type: this.type,
137+
skipAccelerationWait: this.skipAccelerationWait,
134138
});
135139
return this.needDeploy;
136140
}

src/subCommands/deploy/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class Deploy {
3636
alias: {
3737
'assume-yes': 'y',
3838
},
39-
boolean: ['skip-push', 'async_invoke_config'],
39+
boolean: ['skip-push', 'async_invoke_config', 'skip-acceleration-wait'],
4040
});
4141

4242
// TODO: 更完善的验证
@@ -53,6 +53,7 @@ export default class Deploy {
5353
'async-invoke-config': async_invoke_config,
5454
'assume-yes': yes,
5555
'skip-push': skipPush,
56+
'skip-acceleration-wait': skipAccelerationWait,
5657
} = this.opts;
5758
logger.debug('parse argv:');
5859
logger.debug(this.opts);
@@ -64,6 +65,7 @@ export default class Deploy {
6465
type,
6566
yes,
6667
skipPush,
68+
skipAccelerationWait,
6769
}); // function
6870
}
6971
if (deployAll || trigger) {

0 commit comments

Comments
 (0)