Skip to content

Commit a260bab

Browse files
committed
feat(orap): task load add context options
1 parent d695bf8 commit a260bab

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/orap/task/storable.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ export abstract class TaskStorable extends TaskBase {
2525
return (this.constructor as typeof TaskStorable).taskTtlDone
2626
}
2727

28-
static async _load<T extends TaskStorable>(this: Constructor<T>, sm: StoreManager): Promise<T> {
28+
// Factory method to create an instance with the necessary context
29+
static createInstance<T extends TaskStorable>(this: Constructor<T>, context?: Partial<T>): T {
2930
const instance = new this()
31+
Object.assign(instance, context)
32+
return instance
33+
}
34+
35+
static async _load<T extends TaskStorable>(this: Constructor<T>, sm: StoreManager, context?: Partial<T>): Promise<T> {
36+
const instance = (this as any).createInstance(context)
3037
// get all task keys
3138
const keys = await sm.keys(`${instance.getTaskPrefix()}*`, true)
3239
// get the first task (del when finish)
@@ -35,8 +42,8 @@ export abstract class TaskStorable extends TaskBase {
3542
return instance.fromString(serializedTask)
3643
}
3744

38-
static async load<T extends TaskStorable>(this: Constructor<T>, sm: StoreManager): Promise<T> {
39-
return await (this as any)._load(sm)
45+
static async load<T extends TaskStorable>(this: Constructor<T>, sm: StoreManager, context?: Partial<T>): Promise<T> {
46+
return await (this as any)._load(sm, context)
4047
}
4148

4249
async save(sm: StoreManager) {

0 commit comments

Comments
 (0)