'Dramatiq: Getting the worker name within the actor function

Does Dramatiq offer a way to get some sort of a human-readable name of the worker within the @dramatiq.actor function? I would use this to separate log lines from different works.

For example, something like dramatiq-process-1-worker-3.

@dramatiq.actor(broker=redis_broker, store_results=True, result_ttl=10*1000)
def ping():
     # Log worker name here


Solution 1:[1]

  • you can use the CurrentMessage middllware
from dramatiq.middleware import CurrentMessage

@dramatiq.actor(broker=redis_broker, store_results=True, result_ttl=10*1000)
def ping():
    msg = CurrentMessage.get_current_message()
    print(msg.actor_name)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tal Leibman