Skip to content

Instantly share code, notes, and snippets.

@SiestaMadokaist
Created April 29, 2025 16:25
Show Gist options
  • Save SiestaMadokaist/b15dc77f980f288d907d3355ae401cdc to your computer and use it in GitHub Desktop.
Save SiestaMadokaist/b15dc77f980f288d907d3355ae401cdc to your computer and use it in GitHub Desktop.
class ActionGenerate {
....
workDone() {
return this.props.workDone;
}
workToDo(): IPromptParam[] {
const notDone: IPromptParam[] = [];
for (const r of this.props.resource){
if (state.skipped < this.props.workDone) {
state += r.n_iter
}
notDone.push(r)
}
}
async updateProgress(progressDone: number): Promise<void> {
const resp = await this.dynamoClient(updateComand)
if (resp.prioScore != this.props.prioScore) {
await this.updateStatus('pending');
throw new JobReprioritized(...)
}
if (resp.currentStatus != 'running') { throw new JobCancelled }
}
async process(param: IPromptParam) {
...stuffs
await this.updateProgress(this.workDone + param.n_iter)
}
async processAll() {
await this.updateStatus('running');
const todos = this.workToDo();
for (const todo of todos) {
const resp = await this.process(todo).catch((e) => e);
if (resp instanceof JobReprioritized) { return; }
if (resp instanceof Error) { break; }
}
await this.updateStatus('completed');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment