Effect-TS / cluster

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactor interface of AtLeastOnceStorage

mattiamanzati opened this issue · comments

Right now the interface is too specific and tight to the concept of a cluster,
we should maybe revisit that and make it so its more tight to the message instead.
We could align more to the api style of effect/platform's KeyValueStore. (and cluster-platform could provide a storage backed on that)
API would look like:

Need to experiment because I am not a fan of generics in services, but I could see that being nicer dx wise.

export interface AtLeastOnceStorage<Msg extends Message.Message.Any> {
  readonly [AtLeastOnceStorageTypeId]: AtLeastOnceStorageTypeId

  /**
   * Stores a message into the storage, eventually returning the already existing message state as result in the storage
   */
  upsert<Msg extends Message.Message.Any>(
    message: Msg
  ): Effect.Effect<void>

  /**
   * Marks the message as processed, so no more send attempt will occur
   */
  markAsProcessed<Msg extends Message.Message.Any>(
    message: Msg
  ): Effect.Effect<void>

  /**
   * Gets a set of messages that will be sent to the local Pod as second attempt
   */
  sweepPending: Stream.Stream<Msg>
}