This module contains the primary Queue which can be used to create and manage queues.
Returns the Queue object with the given name. If the user passes optional config dictionary with details for Redis server, it will connect to that instance. By default it connects to the localhost.
Creates the connection with the redis server. Return True if the connection works, else returns False. It does not take any arguments.
Returns: | Boolean value |
---|
Note
After creating the Queue object the user should call the connect method so create the connection.
>>> from retask.queue import Queue
>>> q = Queue('test')
>>> q.connect()
True
Returns a Task object from the queue. Returns None if the queue is empty.
Returns: | Task object from the queue |
---|
If the queue is not connected then it will raise retask.ConnectionError
>>> from retask.queue import Queue
>>> q = Queue('test')
>>> q.connect()
True
>>> t = q.dequeue()
>>> print t.data
{u'name': u'kushal'}
Enqueues the given Task object to the queue and returns a tuple. Value in index 0 is Boolean explaining the enqueue operation is a success or not. Value at index 1 is string with error/success message (if any).
Parameters: | task – :Task object |
---|---|
Returns: | Tuple with Boolean value and string message. |
If the queue is not connected then it will raise retask.ConnectionError.
>>> from retask.queue import Queue
>>> q = Queue('test')
>>> q.connect()
True
>>> from retask.task import Task
>>> task = Task({'name':'kushal'})
>>> q.enqueue(task)
(True, 'Pushed')
Gives the length of the queue. Returns None if the queue is not connected.
If the queue is not connected then it will raise retask.ConnectionError.