malthe / pq

A PostgreSQL job queueing system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tasks PQ queue_class isn't used

ulope opened this issue · comments

The tasks PQ() class' queue_class attribute isn't being used during instantiating since the base PQ()'s __init__() method hardcodes the default queue class to Queue (from __init__.py):

self.queue_class = kwargs.pop('queue_class', Queue)

A simple fix would be to add a queue_class = Queue to the base PQ and change the line in __init__() to:

self.queue_class = kwargs.pop('queue_class', self.queue_class)

PS: It might also be a good idea to rename the task varieties of PQ and Queue to TaskPQ and TaskQueue to avoid confusion (which might be noticeable from this report)

I'm experiencing this error and I assume it has something to do with this issue:

>>> from pq.tasks import PQ
>>> from psycopg2 import connect as psqlconnect
>>> database_url = "..."
>>> pgconn = psqlconnect(database_url)
>>> p = PQ(pgconn)
>>> tq = p['tasks']
>>> @tq.task()
... def hi():
...   pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Queue' object has no attribute 'task'

In order to fix this I had to patch the queue_class attribute with Queue class from pq.tasks, like this:

>>> from pq.tasks import PQ
>>> from psycopg2 import connect as psqlconnect
>>> database_url = "..."
>>> pgconn = psqlconnect(database_url)
>>> p = PQ(pgconn)
>>> import pq
>>> p.queue_class = pq.tasks.Queue
>>> tq = p['tasks']
>>> @tq.task()
... def hi():
...   pass
... 
>>>