malthe / pq

A PostgreSQL job queueing system
376 stars 41 forks source link

Get id of current task #58

Closed danilaeremin closed 4 years ago

danilaeremin commented 4 years ago

Any mechanism for getting task id in executor.

I can get it via inspect module (get local variable job in Queue.perform). But it's not very good approach.

I see several ways of implementation: 1) Thread-local variable and job_id property. It's not safe in async functions 2) Same as 1) but with contextvars module. This will require Python 3.7 or back port module. 3) Determine if function has keyword argument job_id and pass it in such case.

I can make pull request with any of the options if will be decision about implementation.

malthe commented 4 years ago

I think it might be cleaner then to simply provide job_id as the first positional argument. Users of the tasks module would then have to update their code.

danilaeremin commented 4 years ago

Yes, it's simplest solution (actually I have such changes locally) I will create Pull Request