Skip to content

Instantly share code, notes, and snippets.

@bwmcadams
Created July 5, 2011 20:45
Show Gist options
  • Save bwmcadams/1065879 to your computer and use it in GitHub Desktop.
Save bwmcadams/1065879 to your computer and use it in GitHub Desktop.
FindAndRemove Snippet
def dequeue: MessageInvocation = withErrorHandling {
/**
* Retrieves first item in natural order (oldest first, assuming no modification/move)
* Waits 3 seconds for now for a message, else pops back out.
* TODO - How do we handle fetch, but sleep if nothing is in there cleanly?
* TODO - Should we have a specific query in place? Which way do we sort?
* TODO - Error handling version!
*/
val msgInvocation = new DefaultPromise[MessageInvocation](3000)
db.findAndRemove(collName)(Document.empty) { msg: MongoDurableMessage =>
EventHandler.debug(this,
"\nDEQUEUING message in mongo-based mailbox [%s]".format(msg))
msgInvocation.completeWithResult(msg.messageInvocation())
EventHandler.debug(this,
"\nDEQUEUING messageInvocation in mongo-based mailbox [%s]".format(msgInvocation))
}
msgInvocation.get
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment