Skip to content

Commit

Permalink
add scheduler to services
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornos committed Oct 24, 2023
1 parent 84ce96b commit 3e9015b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/services/notification/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@ import { ulid } from 'ulidx';

import version from '../../version.js';
import { QuerySubscription, XcmMessageNotify } from '../monitoring/types.js';
import { Family, Logger, Services } from 'services/types.js';
import { Logger, Services } from 'services/types.js';

import { Notifier } from './types.js';
import { Scheduler } from 'services/persistence/scheduler.js';

export const Delivered = Symbol('delivered');

export class WebhookNotifier
extends Stream.EventEmitter
implements Notifier {
#log: Logger;
#notis: Family;
#scheduler: Scheduler;

constructor({ log, storage: { root: db } }: Services) {
constructor({ log, scheduler }: Services) {
super();

this.#log = log;
this.#notis = db.sublevel<string, XcmMessageNotify>(
'noti:whook', {
valueEncoding: 'json'
});
// TODO: retry pendings on constructor or on start?
this.#scheduler = scheduler;
}

async notify(
Expand Down
2 changes: 2 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Janitor } from './persistence/janitor.js';
import { ServiceConfiguration } from './configuration.js';
import Connector from './networking/connector.js';
import { FastifyBaseLogger } from 'fastify';
import { Scheduler } from './persistence/scheduler.js';

export type DB<F = Buffer | Uint8Array | string, K = string, V = any> = AbstractLevel<F, K, V>;
export type Family<F = Buffer | Uint8Array | string, K = string, V = any> = AbstractSublevel<DB, F, K, V>;
Expand All @@ -22,6 +23,7 @@ export type Services = {
subs: SubsStore
},
janitor: Janitor,
scheduler: Scheduler,
config: ServiceConfiguration,
connector: Connector
}
2 changes: 2 additions & 0 deletions src/test/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Janitor } from '../services/persistence/janitor.js';
import { $ServiceConfiguration } from '../services/configuration.js';
import Connector from '../services/networking/connector.js';
import { _configToml } from './data.js';
import { Scheduler } from '../services/persistence/scheduler.js';

export const _log = pino({
enabled: false
Expand All @@ -24,6 +25,7 @@ export const _services = {
root: new MemoryLevel(),
subs: {} as unknown as SubsStore
},
scheduler: {} as unknown as Scheduler,
janitor: {
schedule: () => {}
} as unknown as Janitor
Expand Down

0 comments on commit 3e9015b

Please sign in to comment.