Reputation: 25739
I have a little Play! application(2.1, scala) which acts as a RESTful front-end for a Java library. This web app queues tasks for background processing using:
Akka.system.scheduler.scheduleOnce(Duration(0, SECONDS)) {
new TaskWorker().run(batchId)
}
in Tasks
controller.
The goal is to immediately start heavy processing by the Java library, but in the background.
In advent of Scala 2.10 and its futures and promises, will it make more sense to refactor the queuing to leverage this new API?
In general, I'm looking for a way to be able to perform background processing as currently implemented by Resque Ruby library, but perhaps having an in-process memory queue.(Redis-backed queue would be fine too).
Upvotes: 1
Views: 1322
Reputation: 52
use Akka actor
case class BatchTask(id: Int)
class TaskActor extends Actor {
def receive = {
case BatchTask(batchId) => new TaskWorker().run(batchId)
}
}
val taskWorker = context.actorOf(Props[TaskActor])
taskWorker ! BatchTask(batchId1)
taskWorker ! BatchTask(batchId2)
taskWorker ! BatchTask(batchId3)
Upvotes: 1