Makes sure that no duplicated tasks are enqueued.
429811
def no_duplicates(function, *args, **kwargs):
    
    @wraps(function)
    def wrapper(self, *args, **kwargs):
        key = generate_key(function, *args, **kwargs)
        try:
            function(self, *args, **kwargs)
        finally:
            logging.info('Removing key %s', key)
            cache.delete(key)

    return wrapper
175604
def _ensure_counter(self):
        """"""
        if not isinstance(self.sync_counter, self._SynchronizationManager):
            self.sync_counter = self._SynchronizationManager()
1285794
def enq(self, task):
        
        if not self._stop.is_set():
            self._inq.put(task)
        else:
            raise RuntimeError("Attempted to enqueue an operation while "
                               "multi pool was shutdown!")
948016
def cleanup(self, sched, coro):
        """"""
        try:
            sched.sigwait[self.name].remove((self, coro))
        except ValueError:
            pass
        return True
775065
synchronized void restart()
    {
        TransactionTask task = m_backlog.getFirst();
        if (task.needCoordination() && m_scoreboardEnabled) {
            coordinatedTaskQueueOffer(task);
        } else {
            taskQueueOffer(task);
        }
    }
1000657
def reversed_enqueue_task(task)
      RRRSpec.redis.lpush(RRRSpec.make_key(key, 'task_queue'), task.key)
    end
28797
async def clean(self):
        
        for x in self._running_asyncio_tasks:
            x.cancel()
        self._container_had_error = set()
        self._watching = set()
        self._running_asyncio_tasks = set()
971077
def _ensure_worker(self):
        """"""
        while len(self._workers) < self._min_workers or len(self._workers) < self._queue.qsize() < self._max_workers:
            worker = threading.Thread(
                target=self._execute_futures,
                name=self.identifier + '_%d' % time.time(),
            )
            worker.daemon = True
            self._workers.add(worker)
            worker.start()
733899
def enqueue(taskset, recalculate = false)
      RRRSpec.redis.rpush(STATISTICS_UPDATER_QUEUE_KEY,
        {taskset: taskset.key, recalculate: recalculate}.to_json)
    end
72446
def dequeue
      _, line = RRRSpec.redis.blpop(PERSISTER_QUEUE_KEY, 0)
      Taskset.new(line)
    end
727562
function runQueue() {
		var lastReturned = returned instanceof Array ? returned : [returned]
		  , tasks = queued.shift();

		if (tasks) tasks = tasks.tasks;
		returned = undefined;

		if (tasks instanceof Array) {
			for (var t=0,tt=tasks.length; t<tt; t++) {
				tasks[t].apply(taskObject(t),lastReturned);
			};
			return;
		}
		if (typeof tasks == 'object') {
			for (var t in tasks) if (tasks.hasOwnProperty(t)) {
				tasks[t].apply(taskObject(t),lastReturned);
			}
			return;
		}
	}
456441
def on_task_init(self, task_id, task):
        """"""
        try:
            is_eager = task.request.is_eager
        except AttributeError:
            is_eager = False
        if not is_eager:
            self.close_database()
264432
def flush(self):
        """"""
        while not self._queue.empty():
            self._queue.get()
            self._queue.task_done()
        self.close()
120402
def check_for_missed_cleanup():
    
    if get_setting('PRESERVE_ALL'):
        return
    from api.models.tasks import TaskAttempt
    if get_setting('PRESERVE_ON_FAILURE'):
        for task_attempt in TaskAttempt.objects.filter(
                status_is_running=False).filter(
                    status_is_cleaned_up=False).exclude(
                        status_is_failed=True):
            task_attempt.cleanup()
    else:
        for task_attempt in TaskAttempt.objects.filter(
                status_is_running=False).filter(status_is_cleaned_up=False):
            task_attempt.cleanup()
279270
def insert_tasks_ignore_duplicate_names(tasks, queue, *args, **kwargs):
    

    from google.appengine.api import taskqueue

    try:
        inserted = _insert_tasks(tasks, queue, *args, **kwargs)

        return inserted
    except taskqueue.DuplicateTaskNameError:
        # At least one task failed in our batch, attempt to re-insert the
        # remaining tasks.  Named tasks can never be transactional.
        reinsert = _tasks_to_reinsert(tasks, transactional=False)

        count = len(reinsert)
        inserted = len(tasks) - count

        # Our subsequent task inserts should raise TaskAlreadyExistsError at
        # least once, but that will be swallowed by _insert_tasks.
        for task in reinsert:
            inserted += _insert_tasks([task], queue, *args, **kwargs)

        return inserted
1140490
protected final boolean runAllTasksFrom(Queue<Runnable> taskQueue) {
        Runnable task = pollTaskFrom(taskQueue);
        if (task == null) {
            return false;
        }
        for (;;) {
            safeExecute(task);
            task = pollTaskFrom(taskQueue);
            if (task == null) {
                return true;
            }
        }
    }
596887
boolean takeTaskPermit()
    {
        while (true)
        {
            long current = permits.get();
            int taskPermits = taskPermits(current);
            if (taskPermits == 0)
                return false;
            if (permits.compareAndSet(current, updateTaskPermits(current, taskPermits - 1)))
            {
                if (taskPermits == maxTasksQueued && hasRoom.hasWaiters())
                    hasRoom.signalAll();
                return true;
            }
        }
    }