malthe/pq

Wait on a job?

JohnEmhoff opened this issue · 3 comments

Is there any mechanism to wait for a job to complete? I assume not because there doesn't seem to be any job tracking beyond what time it was dequeued (rather than finished), but thought I'd ask in case I missed something.

That might be an interesting feature, something which would be easy to implement as well. But it's not in there right now.

@JohnEmhoff would you be able to use the same transaction for performing work as well as getting the item?

while True:
    with queue as cursor:
        task = queue.get(timeout=10)
        if task is None:
            continue
        # do work
        # cursor.execute("...")
    # the transaction will be committed when the `with queue as cursor` context exits

Yep, that sounds like a good approach