Example #1
0
    def _run(self, hosts, callback, queue_function, *args):
        hosts = to_hosts(hosts, default_domain=self.domain)
        self.total += len(hosts)
        callback = _prepare_connection(callback)
        task = Task(self.workqueue)
        for host in hosts:
            name = host.get_name()
            data = {"host": host}
            job_id = queue_function(callback, name, *args, data=data)
            if job_id is not None:
                task.add_job_id(job_id)

        if task.is_completed():
            self._dbg(2, "No jobs enqueued.")
            return None

        self._dbg(2, "All jobs enqueued.")
        return task
Example #2
0
    def _run(self, hosts, callback, queue_function, *args):
        hosts = to_hosts(hosts, default_domain=self.domain)
        self.total += len(hosts)
        callback = _prepare_connection(callback)
        task = Task(self.workqueue)
        for host in hosts:
            name = host.get_name()
            data = {'host': host}
            job_id = queue_function(callback, name, *args, data=data)
            if job_id is not None:
                task.add_job_id(job_id)

        if task.is_completed():
            self._dbg(2, 'No jobs enqueued.')
            return None

        self._dbg(2, 'All jobs enqueued.')
        return task
Example #3
0
    def testWait(self):
        task = Task(self.wq)
        self.assertEqual(task.is_completed(), True)

        job1 = Thread(1, object, 'foo1', None)
        job2 = Thread(2, object, 'foo2', None)
        task.add_job_id(job1.id)
        task.add_job_id(job2.id)
        self.assertEqual(task.is_completed(), False)

        self.wq.job_succeeded_event(job1)
        self.assertEqual(task.is_completed(), False)
        self.wq.job_succeeded_event(job2)
        self.assertEqual(task.is_completed(), True)
Example #4
0
    def enqueue(self, function, name = None, attempts = 1):
        """
        Places the given function in the queue and calls it as soon
        as a thread is available. To pass additional arguments to the
        callback, use Python's functools.partial().

        :type  function: function
        :param function: The function to execute.
        :type  name: string
        :param name: A name for the task.
        :type  attempts: int
        :param attempts: The number of attempts on failure.
        :rtype:  object
        :return: An object representing the task.
        """
        self.total += 1
        task   = Task(self.workqueue)
        job_id = self.workqueue.enqueue(function, name, attempts)
        if job_id is not None:
            task.add_job_id(job_id)
        self._dbg(2, 'Function enqueued.')
        return task
Example #5
0
    def enqueue(self, function, name=None, attempts=1):
        """
        Places the given function in the queue and calls it as soon
        as a thread is available. To pass additional arguments to the
        callback, use Python's functools.partial().

        @type  function: function
        @param function: The function to execute.
        @type  name: string
        @param name: A name for the task.
        @type  attempts: int
        @param attempts: The number of attempts on failure.
        @rtype:  object
        @return: An object representing the task.
        """
        self.total += 1
        task = Task(self.workqueue)
        job_id = self.workqueue.enqueue(function, name, attempts)
        if job_id is not None:
            task.add_job_id(job_id)
        self._dbg(2, "Function enqueued.")
        return task
Example #6
0
    def testWait(self):
        task = Task(self.wq)
        self.assertEqual(task.is_completed(), True)

        job1 = Thread(1, object, 'foo1', None)
        job2 = Thread(2, object, 'foo2', None)
        task.add_job_id(job1.id)
        task.add_job_id(job2.id)
        self.assertEqual(task.is_completed(), False)

        self.wq.job_succeeded_event(job1)
        self.assertEqual(task.is_completed(), False)
        self.wq.job_succeeded_event(job2)
        self.assertEqual(task.is_completed(), True)
Example #7
0
 def testIsCompleted(self):
     task = Task(self.wq)
     task.add_job_id(123)
     task.wait() # Returns immediately because the id is not known.
Example #8
0
 def testIsCompleted(self):
     task = Task(self.wq)
     task.add_job_id(123)
     task.wait()  # Returns immediately because the id is not known.
Example #9
0
 def testConstructor(self):
     task = Task(self.wq)