Skip to content

Instantly share code, notes, and snippets.

@ShahOdin
Last active December 7, 2019 01:58
Show Gist options
  • Save ShahOdin/210f7760b0e1e1db129b9bf2804441f5 to your computer and use it in GitHub Desktop.
Save ShahOdin/210f7760b0e1e1db129b9bf2804441f5 to your computer and use it in GitHub Desktop.
storing successes and failures over time
import cats.data.{Ior, NonEmptyList, NonEmptySet}
import io.circe.Json
object demo2 {
type TimeStamp = Long
type Identifier = Long //unique identifier, ie: ccid + streaming-platform perhaps?
type Reason = String
//Having two tables, storing only validated data in the Success table, and storing unavailability reasons in the other table.
//the difficulty is in gluing the two together, both at the data store level as well
//as at the code leve. (can be very easy at the code level with IOR)
case class DataEntry(id: Identifier, timeStamp: TimeStamp, payLoad: Json, complete: Boolean)
case class ValidationFailures(id: Identifier, timeStamp: TimeStamp, sources: NonEmptySet[Identifier], reasons: NonEmptyList[Reason])
def getData1(id: Identifier): Ior[ValidationFailures, DataEntry] = ???
//storing everything in one table. slightly harder to model in postgres. advantage is we always get consistent data.
// maybe the formatting is harder to model
sealed trait Availability
object Availability {
case object Availabile extends Availability
case class UnAvailable(sources: NonEmptySet[Identifier], reasons: NonEmptyList[Reason])
}
case class DataEntry2(id: Identifier, payload: Json, timeStamp: TimeStamp, availability: Availability)
def getData2(id: Identifier): DataEntry2 = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment