@@ -2,6 +2,7 @@ import * as cronParser from "cron-parser";
2
2
import { ErrorCodes , ResonateError } from "../errors" ;
3
3
import { ILogger } from "../logger" ;
4
4
import { Logger } from "../loggers/logger" ;
5
+ import { StoreOptions } from "../options" ;
5
6
import {
6
7
DurablePromise ,
7
8
PendingPromise ,
@@ -26,18 +27,22 @@ export class LocalStore implements IStore {
26
27
public schedules : LocalScheduleStore ;
27
28
public locks : LocalLockStore ;
28
29
30
+ public readonly logger : ILogger ;
31
+
29
32
private toSchedule : Schedule [ ] = [ ] ;
30
33
private next : number | undefined = undefined ;
31
34
32
35
constructor (
33
- private logger : ILogger = new Logger ( ) ,
36
+ opts : Partial < StoreOptions > = { } ,
34
37
promiseStorage : IStorage < DurablePromise > = new WithTimeout ( new MemoryStorage < DurablePromise > ( ) ) ,
35
38
scheduleStorage : IStorage < Schedule > = new MemoryStorage < Schedule > ( ) ,
36
39
lockStorage : IStorage < { id : string ; eid : string } > = new MemoryStorage < { id : string ; eid : string } > ( ) ,
37
40
) {
38
- this . promises = new LocalPromiseStore ( promiseStorage ) ;
39
- this . schedules = new LocalScheduleStore ( scheduleStorage , this ) ;
40
- this . locks = new LocalLockStore ( lockStorage ) ;
41
+ this . promises = new LocalPromiseStore ( this , promiseStorage ) ;
42
+ this . schedules = new LocalScheduleStore ( this , scheduleStorage ) ;
43
+ this . locks = new LocalLockStore ( this , lockStorage ) ;
44
+
45
+ this . logger = opts . logger ?? new Logger ( ) ;
41
46
42
47
this . init ( ) ;
43
48
}
@@ -115,7 +120,10 @@ export class LocalStore implements IStore {
115
120
}
116
121
117
122
export class LocalPromiseStore implements IPromiseStore {
118
- constructor ( private storage : IStorage < DurablePromise > = new MemoryStorage < DurablePromise > ( ) ) { }
123
+ constructor (
124
+ private store : LocalStore ,
125
+ private storage : IStorage < DurablePromise > ,
126
+ ) { }
119
127
120
128
async create (
121
129
id : string ,
@@ -327,8 +335,8 @@ export class LocalPromiseStore implements IPromiseStore {
327
335
328
336
export class LocalScheduleStore implements IScheduleStore {
329
337
constructor (
330
- private storage : IStorage < Schedule > = new MemoryStorage < Schedule > ( ) ,
331
- private store : LocalStore | undefined = undefined ,
338
+ private store : LocalStore ,
339
+ private storage : IStorage < Schedule > ,
332
340
) { }
333
341
334
342
async create (
@@ -456,7 +464,8 @@ export class LocalScheduleStore implements IScheduleStore {
456
464
457
465
export class LocalLockStore implements ILockStore {
458
466
constructor (
459
- private storage : IStorage < { id : string ; eid : string } > = new MemoryStorage < { id : string ; eid : string } > ( ) ,
467
+ private store : LocalStore ,
468
+ private storage : IStorage < { id : string ; eid : string } > ,
460
469
) { }
461
470
462
471
async tryAcquire ( id : string , eid : string ) : Promise < boolean > {
0 commit comments