Skip to content

Commit

Permalink
fix: TECH review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-taran committed Jan 17, 2025
1 parent 8b6867d commit a21fb3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ISubscriber } from './SubscriberFactory'

type GetIdempotencyKeyFunction<T> = (msg: T, info: IMessageInfo) => string | undefined

export abstract class IdempotencyStorage {
public abstract exists(key: string): Promise<boolean>
export interface IIdempotencyStorage {
exists(key: string): Promise<boolean>

public abstract save(key: string): Promise<void>
save(key: string): Promise<void>
}

export class RedisIdempotencyStorage implements IdempotencyStorage {
export class RedisIdempotencyStorage implements IIdempotencyStorage {
constructor(private readonly redisClient: IRedisClient,
private readonly redisDefaultTtl: number) {}

Expand All @@ -25,7 +25,8 @@ export class RedisIdempotencyStorage implements IdempotencyStorage {
}

public async save(key: string): Promise<void> {
await this.redisClient.setex(key, this.redisDefaultTtl, Buffer.from(new Date()))
const value = Buffer.from(new Date().toISOString())
await this.redisClient.setex(key, this.redisDefaultTtl, value)
}
}

Expand All @@ -34,7 +35,7 @@ export class RedisIdempotencyStorage implements IdempotencyStorage {
* Will check if message was already processed by checking idempotency key in the storage, and will skip it if it was.
* After the message is processed, stores message in the idempotency storage
*/
export abstract class MessageHandlerIdempotent<T = unknown> {
export abstract class IdempotentMessageHandler<T = unknown> {
/**
*
* @param subscriber subscriber to listen to
Expand All @@ -44,7 +45,7 @@ export abstract class MessageHandlerIdempotent<T = unknown> {
*/
protected constructor(
private readonly subscriber: ISubscriber<T>,
private readonly idempotencyStorage: IdempotencyStorage,
private readonly idempotencyStorage: IIdempotencyStorage,
private readonly getIdempotencyKey: GetIdempotencyKeyFunction<T> =
(_: T, info: IMessageInfo) => {
return info.attributes[JOIN_IDEMPOTENCY_KEY]
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from './PublisherFactory'
export * from './Subscriber'
export * from './SubscriberFactory'
export * from './MessageHandler'
export * from './MessageHandlerIdempotent'
export * from './IdempotentMessageHandler'
export * from './ILogger'
export * from './SchemaDeployer'
export * from './PublisherInitializer'

0 comments on commit a21fb3b

Please sign in to comment.