Dramatiq: Getting the worker name within the actor function

681 Views Asked by At

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
1

There are 1 best solutions below

0
Tal Leibman On BEST ANSWER
  • 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)