How to get task results without Results middleware


At you say that:

Dramatiq can store actor return values to Memcached and Redis by leveraging the Results middleware. In most cases you can get by without needing this capability so the middleware is not turned on by default.

As I’m still getting my head around task runners and message queues, can you explain how I would typically go about saving the results of a task without using the Results middleware? Would it simply mean having a line of code in the task function itself that saves the results to a database?


Yes, that’s exactly what I meant when I wrote that paragraph. For example, say you have an actor that processes reports; you’d send that actor a message with the id of the report you want it to process and it’d take care of grabbing the report from the DB, modifying it and then saving it back:

def process_report(report_id):
    report = Report.get_by_id(report_id)
    # do something to the report

For a very large number of use cases this will be enough and for the remainder (cases where you want to asynchronously compute a value) you have the results middleware.