예제 #1
0
파일: queue.py 프로젝트: pranjal5215/fastQ
class Queue(object):
    """
    A custom Queue API for our workers so that we can plug an play with
    multiple Queue implementations.
    """

    def __init__(self, name):
        if isinstance(name, basestring) and name.strip():
            self.q = RetaskQueue(name)
            self.q.connect()
            self.name = name
        else:
            raise QueueException(
                "Bad value for 'name'. 'name' has to be a non empty string.")

    def get(self, count=1, wait=False):
        """
        Get task from Queue.

        Args:
            wait: A boolean deciding whether to retrieve a task
                  from queue in a blocking fashion or not.
        Returns:
            A list of retask.Task instances.
        """
        tasks = []
        for n in range(count or 1):
            if wait:
                task = self.q.wait()
            else:
                task = self.q.dequeue()
            tasks.append(task)
        return tasks

    def put(self, data):
        """
        Create a task from data and put it to Queue.

        Args:
            data: A dictionary.
        """
        task = Task(data)
        job = self.q.enqueue(task)
        return job

    def send(self, task, data):
        """
        Update result for a task and send it to the producer.

        Args:
            task: A retask.Task instance
            data: A string.
        """
        self.q.send(task, data)

    def __unicode__(self):
         return self.name
예제 #2
0
from retask import Task
from retask import Queue
import time
queue = Queue('example')
queue.connect()
task = queue.wait()
print(task.data)
time.sleep(15)
queue.send(task, "We received your information dear %s" % task.data['user'])

예제 #3
0
 def runTest(self):
     queue = Queue('testqueue')
     queue.connect()
     task = queue.dequeue()
     i = task.data
     self.assertEqual(task.data['name'], 'kushal')
예제 #4
0
 def setUp(self):
     queue = Queue('testqueue')
     queue.connect()
     t = Task({'name': 'kushal'})
     queue.enqueue(t)
예제 #5
0
 def runTest(self):
     queue = Queue('testqueue')
     queue.connect()
     t = Task({'name': 'kushal'})
     self.assertTrue(queue.enqueue(t))
예제 #6
0
 def runTest(self, mock_redis):
     m = mock_redis.return_value
     m.llen.return_value = 2
     queue = Queue('testqueue')
     queue.connect()
     self.assertEqual(queue.length, 2)
예제 #7
0
 def runTest(self):
     queue = Queue('testqueue')
     self.assertTrue(queue.connect())
예제 #8
0
파일: tests.py 프로젝트: asldevi/retask
 def runTest(self):
     queue = Queue('testqueue')
     queue.connect()
     task = queue.dequeue()
     i = task.data
     self.assertEqual(task.data['name'], 'kushal')
예제 #9
0
파일: tests.py 프로젝트: asldevi/retask
 def setUp(self):
     queue = Queue('testqueue')
     queue.connect()
     t = Task({'name':'kushal'})
     queue.enqueue(t)
예제 #10
0
파일: tests.py 프로젝트: asldevi/retask
 def runTest(self):
     queue = Queue('testqueue')
     queue.connect()
     t = Task({'name':'kushal'})
     self.assertTrue(queue.enqueue(t))
예제 #11
0
파일: tests.py 프로젝트: asldevi/retask
 def runTest(self, mock_redis):
     m = mock_redis.return_value
     m.llen.return_value = 2
     queue = Queue('testqueue')
     queue.connect()
     self.assertEqual(queue.length, 2)
예제 #12
0
파일: tests.py 프로젝트: asldevi/retask
 def runTest(self):
     queue = Queue('testqueue')
     self.assertTrue(queue.connect())
예제 #13
0
 def runTest(self):
     queue = Queue('lambda')
     queue.connect()
     results = queue.names()
     self.assertEqual(results[0], 'retaskqueue-lambda')