Skip to content

Commit

Permalink
enable real sinks instead of mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Apr 22, 2024
1 parent cafeef9 commit 6f58df5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 63 deletions.
85 changes: 45 additions & 40 deletions src/new-proposals-monitoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DialectSdkNotification,

Check warning on line 4 in src/new-proposals-monitoring.service.ts

View workflow job for this annotation

GitHub Actions / Integration

'DialectSdkNotification' is defined but never used
Monitor,
Monitors,
NotificationSink,
Pipelines,
} from '@dialectlabs/monitor';
import { Duration } from 'luxon';
Expand All @@ -18,11 +19,15 @@ import {
import { ConsoleNotificationSink } from './console-notification-sink';

Check warning on line 19 in src/new-proposals-monitoring.service.ts

View workflow job for this annotation

GitHub Actions / Integration

'ConsoleNotificationSink' is defined but never used
import { OnEvent } from '@nestjs/event-emitter';
import { CachingEventType } from './realms-cache';
import {
TwitterNotification,
TwitterNotificationsSink,
} from './twitter-notifications-sink';

@Injectable()
export class NewProposalsMonitoringService {
// private readonly twitterNotificationsSink: NotificationSink<TwitterNotification> =
// new TwitterNotificationsSink();
private readonly twitterNotificationsSink: NotificationSink<TwitterNotification> =
new TwitterNotificationsSink();

private readonly logger = new Logger(NewProposalsMonitoringService.name);

Expand Down Expand Up @@ -61,30 +66,7 @@ export class NewProposalsMonitoringService {
id: NOTIF_TYPE_ID_PROPOSALS,
},
})
.custom<DialectSdkNotification>(
({ value, context }) => {
const realmName: string = context.origin.realm.account.name;
const realmId: string = context.origin.realm.pubkey.toBase58();
const message: string = this.constructMessage(
realmName,
realmId,
value,
);
this.logger.log(
`Sending message for ${context.origin.subscribers.length} subscribers of realm ${realmId} : ${message}`,
);
return {
title: `New proposal for ${realmName}`,
message,
};
},
new ConsoleNotificationSink(),
{
dispatch: 'multicast',
to: (ctx) => ctx.origin.subscribers,
},
)
// .dialectSdk(
// .custom<DialectSdkNotification>(
// ({ value, context }) => {
// const realmName: string = context.origin.realm.account.name;
// const realmId: string = context.origin.realm.pubkey.toBase58();
Expand All @@ -101,23 +83,46 @@ export class NewProposalsMonitoringService {
// message,
// };
// },
// { dispatch: 'multicast', to: ({ origin }) => origin.subscribers },
// )
// .custom<TwitterNotification>(
// ({ value, context }) => {
// const realmName: string = context.origin.realm.account.name;
// const realmId: string = context.origin.realm.pubkey.toBase58();
// const message = this.constructMessage(realmName, realmId, value);
// this.logger.log(`Sending tweet for ${realmName} : ${message}`);
// return {
// message,
// };
// },
// this.twitterNotificationsSink,
// new ConsoleNotificationSink(),
// {
// dispatch: 'broadcast',
// dispatch: 'multicast',
// to: (ctx) => ctx.origin.subscribers,
// },
// )
.dialectSdk(
({ value, context }) => {
const realmName: string = context.origin.realm.account.name;
const realmId: string = context.origin.realm.pubkey.toBase58();
const message: string = this.constructMessage(
realmName,
realmId,
value,
);
this.logger.log(
`Sending message for ${context.origin.subscribers.length} subscribers of realm ${realmId} : ${message}`,
);
return {
title: `New proposal for ${realmName}`,
message,
};
},
{ dispatch: 'multicast', to: ({ origin }) => origin.subscribers },
)
.custom<TwitterNotification>(
({ value, context }) => {
const realmName: string = context.origin.realm.account.name;
const realmId: string = context.origin.realm.pubkey.toBase58();
const message = this.constructMessage(realmName, realmId, value);
this.logger.log(`Sending tweet for ${realmName} : ${message}`);
return {
message,
};
},
this.twitterNotificationsSink,
{
dispatch: 'broadcast',
},
)
.and()
.build()
);
Expand Down
49 changes: 26 additions & 23 deletions src/proposal-state-monitoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,7 @@ export class ProposalStateChangeMonitoringService {
id: NOTIF_TYPE_ID_PROPOSALS,
},
})
// .dialectSdk(
// ({ value, context }) => {
// const realmId: string = context.origin.realm.pubkey.toBase58();
// const notification = this.constructNotification(
// context.origin.realm.account,
// realmId,
// value,
// );
// this.logger.log(
// `Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId}
// ${notification.title}
// ${notification.message}
// `,
// );
// return notification;
// },
// { dispatch: 'multicast', to: ({ origin }) => origin.realmSubscribers },
// )
.custom<DialectSdkNotification>(
.dialectSdk(
({ value, context }) => {
const realmId: string = context.origin.realm.pubkey.toBase58();
const notification = this.constructNotification(
Expand All @@ -112,18 +94,39 @@ export class ProposalStateChangeMonitoringService {
);
this.logger.log(
`Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId}
${notification.title}
${notification.message}
`,
${notification.title}
${notification.message}
`,
);
return notification;
},
new ConsoleNotificationSink(),
{
dispatch: 'multicast',
to: ({ origin }) => origin.realmSubscribers,
},
)
// .custom<DialectSdkNotification>(
// ({ value, context }) => {
// const realmId: string = context.origin.realm.pubkey.toBase58();
// const notification = this.constructNotification(
// context.origin.realm.account,
// realmId,
// value,
// );
// this.logger.log(
// `Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId}
// ${notification.title}
// ${notification.message}
// `,
// );
// return notification;
// },
// new ConsoleNotificationSink(),
// {
// dispatch: 'multicast',
// to: ({ origin }) => origin.realmSubscribers,
// },
// )
.and()
.build()
);
Expand Down

0 comments on commit 6f58df5

Please sign in to comment.