refactor: huawei

This commit is contained in:
xiaojunnuo
2023-05-09 14:11:01 +08:00
parent f489c59ca3
commit 8c152371a1
6 changed files with 29 additions and 20 deletions
+15 -6
View File
@@ -1,8 +1,10 @@
import { IStorage, MemoryStorage } from "./storage";
export interface IContext {
get(key: string): Promise<any>;
set(key: string, value: any): Promise<void>;
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<void>;
getObj(key: string): Promise<any>;
setObj(key: string, value: any): Promise<void>;
}
export class ContextFactory {
@@ -32,8 +34,15 @@ export class StorageContext implements IContext {
this.scope = scope;
this.namespace = namespace;
}
async get(key: string): Promise<any> {
const str = await this.storage.get(this.scope, this.namespace, key);
async get(key: string) {
return await this.storage.get(this.scope, this.namespace, key);
}
async set(key: string, value: string) {
return await this.storage.set(this.scope, this.namespace, key, value);
}
async getObj(key: string): Promise<any> {
const str = await this.get(key);
if (str) {
const store = JSON.parse(str);
return store.value;
@@ -41,7 +50,7 @@ export class StorageContext implements IContext {
return null;
}
async set(key: string, value: any) {
await this.storage.set(this.scope, this.namespace, key, JSON.stringify({ value }));
async setObj(key: string, value: any) {
await this.set(key, JSON.stringify({ value }));
}
}
+4 -4
View File
@@ -53,8 +53,8 @@ export class Executor {
if (runnable.strategy?.runStrategy === RunStrategy.SkipWhenSucceed) {
//如果是成功后跳过策略
const lastResult = await this.pipelineContext.get(contextKey);
const lastInput = await this.pipelineContext.get(inputKey);
const lastResult = await this.pipelineContext.getObj(contextKey);
const lastInput = await this.pipelineContext.getObj(inputKey);
let inputChanged = false;
//TODO 参数不变
if (runnableType === "step") {
@@ -73,12 +73,12 @@ export class Executor {
try {
await run();
this.runtime.success(runnable);
await this.pipelineContext.set(contextKey, ResultType.success);
await this.pipelineContext.setObj(contextKey, ResultType.success);
await this.onChanged(this.runtime);
return ResultType.success;
} catch (e: any) {
this.runtime.error(runnable, e);
await this.pipelineContext.set(contextKey, ResultType.error);
await this.pipelineContext.setObj(contextKey, ResultType.error);
await this.onChanged(this.runtime);
throw e;
} finally {