Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
331 stars 77 forks source link

Access actor's uuid inside the function? #80

Closed knguyen1794 closed 3 years ago

knguyen1794 commented 3 years ago

The django_dramatiq app creates a model with uuid to differentiate different tasks.

Now I'm trying to visualize the runs with some extra information generated during the run of the tasks. In order to do that, I need a link this information with the task uuid in the table created by django_dramatiq.

Is there anyway that I can access the uuid inside the function?

@dramatiq.actor
def my_task():
   # Is there anyway to access the uuid here?
Bogdanp commented 3 years ago

The UUID of a Task is the message's id, which you can grab using the CurrentMessage middleware.

See https://dramatiq.io/reference.html#dramatiq.middleware.CurrentMessage

Hope that helps!