Setup Scala 2.11.4, Playframework 2.3.7, Reacivemongo (0.10.5.0.akka23/0.11.0-SNAPSHOT tried with both).
We have a collection with 18'000 entities, processing this collection in asynchronous manner, using Enumerator/Iteratee approach.
Case 1. Processing is simple (extraction of entities to CSV format and sending them in chunks as a REST response) everything works fine, all records are extracted and processed.
Case 2. Processing involves calculations which take up to 10 seconds, and updating of records after calculation, calculation is done with foreach Iteratee, which updates number of processed entities in internal task tracker. The processing might take a while, but that's OK
Patient.findByClient(clientName) &>
Enumeratee.mapM(patient => {
val evaluatedAndSaveTask = patient.
evaluate(parser).
flatMap(patientOpt =>
patientOpt.
map(evaluatedPatient => evaluatedPatient.saveAndGet().map(Some(_))).
getOrElse(Future.successful(None))
)
evaluatedAndSaveTask.recover({
case t =>
t.printStackTrace()
None
})
})
// Step 2.1. Running evaluation process through Iteratee
val evaluationTask = evaluation run Iteratee.foreach(patientOpt => {
collection.update(Json.obj("clientName" -> clientName), Json.obj("$inc" -> Json.obj("processedPatients" -> 1))))
)
// Step 2.3. Log errors
evaluationTask.onSuccess({ case _ => Patient.LOG.info("PatientEvaluation DONE") })
evaluationTask.onFailure({ case t => {
t.printStackTrace();
Patient.LOG.info("PatientEvaluation FAILED");
}})
In this case only 575 entities get's processed, and Iteratee ends printing out "Patient evaluation DONE".
I removed save from the equation, and it did not help.
Why can that be?