Reputation: 23
I am new to Scala and am using the method def process however getting build errors like "method wasSuccessful in class IOResult is deprecated (since 2.6.0): status is always set to Success(Done) case Success((sftpResult, updateList)) if sftpResult.wasSuccessful =>". My question is how would I then implement this in my code? I apologise if the question seems stupid.
override def process(changedAfter: Option[ZonedDateTime], changedBefore: Option[ZonedDateTime])
(implicit fc: FlowContext): Future[(IOResult, Seq[Operation.Value])] = {
val now = nowUtc
val accountUpdatesFromDeletions: Source[AccountUpdate, NotUsed] =
dbService
.getDeleteActions(before = now)
.map(deletionEventToAccountUpdate)
val result = getAccountUpdates(changedAfter, changedBefore)
.merge(getErrorUpdates)
.merge(accountUpdatesFromDeletions)
.mapAsync(4)(writer.writePSVString)
.viaMat(creditBureauService.sendUpdate)(Keep.right)
.mapAsync(4)(au =>
for {
_ <- dbService.performUpdate(au)
_ <- performActionsDelete(now, au)
} yield au.operation
)
.toMat(Sink.seq)(Keep.both)
.withAttributes(ActorAttributes.supervisionStrategy(decider))
.run()
tupleFutureToFutureTuple(result) andThen {
case Success((sftpResult, updateList)) if sftpResult.wasSuccessful =>
val total = updateList.size
val deleted = updateList.count(_ == Operation.DELETED)
val updated = updateList.count(_ == Operation.UPDATED)
val inserted = updateList.count(_ == Operation.INSERTED)
log.info(s"SUCCESS! Uploaded $total accounts to Equifax.")
log.info(s"There were $deleted deletions, " +
s"$updated updates and " +
s"$inserted insertions to the database")
monitor.gauge("upload.process.batch.successful.total", total)
monitor.gauge("upload.process.batch.successful.deleted", deleted)
monitor.gauge("upload.process.batch.successful.updated", updated)
monitor.gauge("upload.process.batch.successful.inserted", inserted)
case Success((sftpResult, _)) if !sftpResult.wasSuccessful =>
val sw = new StringWriter
sftpResult.getError.printStackTrace(new PrintWriter(sw))
log.error("Failed to send data: " + sw.toString)
monitor.gauge("upload.process.batch.sftp.failed", 1)
case Failure(e: Throwable) =>
val sw = new StringWriter
e.printStackTrace(new PrintWriter(sw))
log.error(sw.toString)
monitor.gauge("upload.process.batch.failed", 1)
}
}
Upvotes: 0
Views: 89
Reputation: 22449
Both wasSuccessful
and getError
have been deprecated since 2.6
. Since IOResult
is in general wrapped in a Future
which by itself already tells whether the I/O operation is a Success or Failure, the status
parameter of a successfully returned IOResult
is in essence redundant, thus is now always set to Success[Done]
.
Given that, you could simplify/refactor your case matching snippet to something like below:
tupleFutureToFutureTuple(result) andThen {
case Success((sftpResult, updateList)) =>
val total = updateList.size
val deleted = updateList.count(_ == Operation.DELETED)
val updated = updateList.count(_ == Operation.UPDATED)
val inserted = updateList.count(_ == Operation.INSERTED)
log.info(s"SUCCESS! Uploaded $total accounts to Equifax.")
log.info(s"There were $deleted deletions, " +
s"$updated updates and " +
s"$inserted insertions to the database")
monitor.gauge("upload.process.batch.successful.total", total)
monitor.gauge("upload.process.batch.successful.deleted", deleted)
monitor.gauge("upload.process.batch.successful.updated", updated)
monitor.gauge("upload.process.batch.successful.inserted", inserted)
case Failure(e: Throwable) =>
val sw = new StringWriter
e.printStackTrace(new PrintWriter(sw))
log.error(sw.toString)
monitor.gauge("upload.process.batch.failed", 1)
}
Upvotes: 1