Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created October 6, 2021 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elyphas/cdf2de0211e65cbfdfb46e3a0f85a23b to your computer and use it in GitHub Desktop.
Save elyphas/cdf2de0211e65cbfdfb46e3a0f85a23b to your computer and use it in GitHub Desktop.
class ComparativeRepository {
val hdlProcessingSideEffects = Handler.create[String]("").unsafeRunSync()
def processingSideEffects = hdlProcessingSideEffects.map {
case "" => None
case msg => Some(div( clear.both, cls:="processingSideEffects", msg))
}
val storeComparative = new StoreComparative()
val eventComparative = PublishSubject[String]()
//val eventComparativePublish = eventComparative.publish
val eventComparativePublish = eventComparative.multicast(Pipe.publish[String])
val cancelEventComparativePublish = eventComparativePublish.connect()
val getMinimosRetensionISR = eventComparativePublish.dump("0").mapEval { case idComparative =>
println("Ha ver, ha ver, changos !!!!!!!!! en el getMinimosRetensionISR")
hdlProcessingSideEffects.onNext("Procesando el Comparativo!")
val payload = Pickle.intoBytes[String](idComparative)
val respondWS = WSMyCeliumAnalytics.ws.send("getMinimosRetensionISR" :: Nil, payload, SendType.WhenConnected, 100 seconds)
respondWS.failed.foreach( x => println(s"################### ERROR getMinimosRetensionISR ####################################: $x "))
respondWS.failed.foreach(println)
Task.suspend {
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage),
result => {
result match {
case Right(value) =>
val unPickle = Unpickle[Either[String, Double]].fromBytes(value)
unPickle match {
case Right(value) =>
storeComparative.store.onNext(storeComparative.UpdateMinimosRetensionISR(value))
println("Procesando con exito getMinimosRetensionISR !!!!!!!!!!")
Right(value)
case Left(error) => Left(error + "--getMinimosRetensionISR")
}
case Left(error) => Left(error)
}
}
)
}
}
val getProcess = eventComparativePublish.dump("0").mapEval { case idComparative =>
hdlProcessingSideEffects.onNext("Procesando el Comparativo!")
val payload = Pickle.intoBytes[String](idComparative)
val respondWS = WSMyCeliumAnalytics.ws.send("getProcess" :: Nil, payload, SendType.WhenConnected, 100 seconds)
respondWS.failed.foreach( x => println(s"################### ERROR getProcess ####################################: $x "))
//respondWS.failed.foreach(println)
Task.suspend {
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage),
result => {
result match {
case Right(value) =>
implicit val datePickler = transformPickler((t: Long) => new java.util.Date(t))(_.getTime)
val unPickle = Unpickle[Either[String, ViewProcess]].fromBytes(value)
unPickle match {
case Right(value) =>
storeComparative.store.onNext(storeComparative.UpdateGralDataOfComparative(value))
println("Procesando con exito getProcess !!!!!!!!!!")
Right(value)
case Left(error) => Left(error + " getProcess")
}
case Left(error) => Left(error)
}
}
)
}
}
val getComparativo = eventComparativePublish.dump("0").mapEval { case idComparative =>
hdlProcessingSideEffects.onNext("Procesando el Comparativo!")
val payload = Pickle.intoBytes[String](idComparative)
val respondWS = WSMyCeliumAnalytics.ws.send("getComparativo" :: Nil, payload, SendType.WhenConnected, 100 seconds)
respondWS.failed.foreach( x => println(s"################### ERROR getProcess ####################################: $x "))
//respondWS.failed.foreach(println)
Task.suspend {
Task.fromFuture(respondWS).redeem( err => Left(err.getMessage),
result => {
result match {
case Right(value) =>
val unPickle = Unpickle[Either[String, List[(QryRow, Comparative)] ]].fromBytes(value)
unPickle match {
case Right(value) =>
storeComparative.store.onNext ( storeComparative.UpdateTenders( value ) )
println("Procesando con exito getComparative !!!!!!!!!!")
Right(value)
case Left(error) => Left(error + " getComparativo")
}
case Left(error) => Left(error)
}
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment