Skip to content

Commit

Permalink
feat: progressive (#551)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Chen <czy88840616@gmail.com>
  • Loading branch information
echosoar and czy88840616 committed Jul 24, 2020
1 parent d8f231c commit 7b0060e
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 217 deletions.
26 changes: 22 additions & 4 deletions packages/faas-cli-command-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class CommandHookCore implements ICommandHooksCore {
private execId: number = Math.ceil(Math.random() * 1000);
private userLifecycle: any = {};
private cwd: string;
private stopLifecycles: string[] = [];

store = new Map();

Expand Down Expand Up @@ -138,6 +139,10 @@ export class CommandHookCore implements ICommandHooksCore {
if (displayHelp) {
return this.displayHelp(commandsArray, commandInfo.usage);
}
await this.execLiftcycle(lifecycleEvents);
}

private async execLiftcycle(lifecycleEvents) {
for (const lifecycle of lifecycleEvents) {
if (this.userLifecycle && this.userLifecycle[lifecycle]) {
this.debug('User Lifecycle', lifecycle);
Expand All @@ -161,6 +166,17 @@ export class CommandHookCore implements ICommandHooksCore {
}
}

// resume stop licycle execute
public async resume(options?) {
if (options) {
if (!this.options.options) {
this.options.options = {};
}
Object.assign(this.options.options, options);
}
await this.execLiftcycle(this.stopLifecycles);
}

// spawn('aliyun:invoke')
public async spawn(commandsArray: string | string[], options?: any) {
let commands: string[] = [];
Expand Down Expand Up @@ -314,19 +330,21 @@ export class CommandHookCore implements ICommandHooksCore {
parentCommandList?: string[]
) {
const allLifecycles: string[] = [];
let isStop = false;
const { stopLifecycle } = this.options;
const parentCommand =
parentCommandList && parentCommandList.length
? `${parentCommandList.join(':')}:`
: '';
if (lifecycleEvents) {
for (const life of lifecycleEvents) {
const liftCycles = isStop ? this.stopLifecycles : allLifecycles;
const tmpLife = `${parentCommand}${command}:${life}`;
allLifecycles.push(`before:${tmpLife}`);
allLifecycles.push(tmpLife);
allLifecycles.push(`after:${tmpLife}`);
liftCycles.push(`before:${tmpLife}`);
liftCycles.push(tmpLife);
liftCycles.push(`after:${tmpLife}`);
if (stopLifecycle === tmpLife) {
return allLifecycles;
isStop = true;
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions packages/faas-cli-command-core/test/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ describe('command-core', () => {
await core.invoke(['invoke']);
assert(result && result.length === 3);
});
it('stop lifecycle and resume', async () => {
const result: string[] = [];
const core = new CommandHookCore({
provider: 'test',
log: {
log: (msg: string) => {
result.push(msg);
},
},
stopLifecycle: 'invoke:one',
});
core.addPlugin(TestPlugin);
await core.ready();
await core.invoke(['invoke']);
assert(result.length === 3);
await core.resume();
assert((result as any).length === 6);
});
it('user lifecycle', async () => {
const cwd = join(__dirname, './fixtures/userLifecycle');
const tmpData = Date.now() + '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1595514742831
1595516163422
2 changes: 1 addition & 1 deletion packages/faas-cli-plugin-invoke/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "dist/index",
"typings": "dist/index.d.ts",
"dependencies": {
"@midwayjs/debugger": "^0.0.3",
"@midwayjs/debugger": "^1.0.0",
"@midwayjs/faas-code-analysis": "^1.1.0",
"@midwayjs/fcli-command-core": "^1.1.2",
"@midwayjs/locate": "^1.0.3",
Expand Down

0 comments on commit 7b0060e

Please sign in to comment.