malthe / pq

A PostgreSQL job queueing system
376 stars 41 forks source link

Wait on a job? #50

Open JohnEmhoff opened 4 years ago

JohnEmhoff commented 4 years ago

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.

malthe commented 4 years ago

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

minyoung commented 4 years ago

@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
JohnEmhoff commented 4 years ago

Yep, that sounds like a good approach