I was wondering what is the best practices for invoking little offline jobs. Examples:
- Send email, once an entity is persisted.
- Update external service when something happens in my app.
- Run an offline calculation and persist it (something which is not part of the critical flow of my app)
- And more..
I am aware of the capabilities of akka actor system , and also scala future.But I am not sure what is the best tool for this kind of use case.
I will go with the onSuccess hook of a future most of the times, and only use actors if I need to hold a state that need to be updated. (onSuccess have it's disadvantages, hard to pushback, and hard to test)
So if we look on a code example:
val myCriticalFlowFuture = dao.doSomething() myCriticalFlowFuture.onSuccess(_ => sendEmail()) myCriticalFlowFuture
dao.doSomething().map(_ => eventBus.publish(SendMailMessage(Payload(email))))
What do you think?