Last active
June 29, 2016 22:49
-
-
Save leogrim/00be2141739051b6d33794e7c7cc848b to your computer and use it in GitHub Desktop.
Juggle - Concurrent Task Processing With a Single Actor - https://medium.com/kifi-engineering/juggle-concurrent-task-processing-with-a-single-actor-ed9f33c713cf
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
trait BatchProcessingActor[T] extends ConcurrentTaskProcessingActor[Seq[T]] { _: Actor => | |
final protected val minConcurrentTasks: Int = 1 | |
final protected val maxConcurrentTasks: Int = 1 | |
final protected def pullTasks(limit: Int): Future[Seq[Seq[T]]] = { | |
if (limit == 1) nextBatch.map(Seq(_).filter(_.nonEmpty))(immediately) else Future.successful(Seq.empty) | |
} | |
final protected def processTasks(tasks: Seq[Seq[T]]): Map[Seq[T], Future[Unit]] = { | |
tasks.map { batch => batch -> processBatch(batch) }.toMap | |
} | |
protected def nextBatch: Future[Seq[T]] | |
protected def processBatch(batch: Seq[T]): Future[Unit] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment