def _run(self, plugin, devices, callback, queue_function, *args): self.total += len(devices) callback = _prepare_plugin(callback) self.task = Task(plugin.DESCRIPTION, self.workqueue) for device in devices: if device in self.failed_devices: continue data = {'device': device} job_id = queue_function(callback, device.name, *args, data=data) if job_id is not None: self.task.add_job_id(job_id) if self.task.is_completed(): self._dbg(2, 'No jobs enqueued.')
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