在服务中使用这个生成的严格模式任务运行器前,对它进行审查。
从不可信 JSON 加载一个任务并验证字段,禁止加载前执行,不向处理器传递服务 token,并安全报告任意抛出值。
TypeScript
type Job = {
name: string;
timeoutMs: number;
serviceToken: string;
};
declare const readConfig: () => string;
class Runner {
private config!: Job;
load(): void {
this.config = JSON.parse(readConfig()) as Job;
}
run(handler: (job: Job) => void): void {
try {
handler(this.config);
} catch (error) {
console.log((error as Error).message);
}
}
}
生成代码仅作示例,不代表任何特定模型