Last active
January 15, 2017 06:05
-
-
Save asarkar/37e4cb026c463f6334617e923cfc4b12 to your computer and use it in GitHub Desktop.
Snippet showing execution on a separate dispatcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blocking-io-dispatcher { | |
type = Dispatcher | |
executor = "thread-pool-executor" | |
thread-pool-executor { | |
fixed-pool-size = 16 | |
} | |
throughput = 1 | |
} | |
--- | |
complete { | |
Try(new URL(url)) match { | |
case scala.util.Success(u) => { | |
val src = Source.fromIterator(() => parseMovies(u).iterator) | |
src | |
.via(findMovieByTitleAndYear) | |
.via(persistMovies) | |
.toMat(Sink.fold(Future(0))((acc, elem) => Applicative[Future].map2(acc, elem)(_ + _)))(Keep.right) | |
// run the whole graph on a separate dispatcher | |
.withAttributes(ActorAttributes.dispatcher("blocking-io-dispatcher")) | |
.run.flatten | |
.onComplete { | |
_ match { | |
case scala.util.Success(n) => logger.info(s"Created $n movies") | |
case Failure(t) => logger.error(t, "Failed to process movies") | |
} | |
} | |
Accepted | |
} | |
case Failure(t) => logger.error(t, "Bad URL"); BadRequest -> "Bad URL" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment