Return queue instances from specified queue names.
    All instances must use the same Redis connection.
3637
def get_queues(*queue_names, **kwargs):
    
    from .settings import QUEUES

    if len(queue_names) <= 1:
        # Return "default" queue if no queue name is specified
        # or one queue with specified name
        return [get_queue(*queue_names, **kwargs)]

    # will return more than one queue
    # import job class only once for all queues
    kwargs['job_class'] = get_job_class(kwargs.pop('job_class', None))

    queue_params = QUEUES[queue_names[0]]
    connection_params = filter_connection_params(queue_params)
    queues = [get_queue(queue_names[0], **kwargs)]

    # do consistency checks while building return list
    for name in queue_names[1:]:
        queue = get_queue(name, **kwargs)
        if type(queue) is not type(queues[0]):
            raise ValueError(
                'Queues must have the same class.'
                '"{0}" and "{1}" have '
                'different classes'.format(name, queue_names[0]))
        if connection_params != filter_connection_params(QUEUES[name]):
            raise ValueError(
                'Queues must have the same redis connection.'
                '"{0}" and "{1}" have '
                'different connections'.format(name, queue_names[0]))
        queues.append(queue)

    return queues
1029511
def get_instances_by_name(name, sort_by_order=('cloud', 'name'), projects=None, raw=True, regions=None, gcp_credentials=None, clouds=SUPPORTED_CLOUDS):
    """"""
    matching_instances = all_clouds_get_instances_by_name(
        name, projects, raw, credentials=gcp_credentials, clouds=clouds)
    if regions:
        matching_instances = [instance for instance in matching_instances if instance.region in regions]
    matching_instances.sort(key=lambda instance: [getattr(instance, field) for field in sort_by_order])
    return matching_instances
373337
def _parse_queues(queues):
        
        if not queues:
            raise ConfigurationException('The queue(s) to use are not defined')

        if isinstance(queues, (list, tuple)):
            for queue_name in queues:
                if not isinstance(queue_name, str):
                    raise ConfigurationException('Queue name "%s" is not a (base)string')

        elif isinstance(queues, basestring):
            queues = str(queues).split(',')

        else:
            raise ConfigurationException('Invalid format for queues names')

        return list(queues)
1154932
def get_jobs_from_queue(self, queue: str, max_jobs: int) -> List[Job]:
        """"""
        rv = list()
        while len(rv) < max_jobs:
            try:
                job_json_string = self._get_queue(queue).get(block=False)
            except Empty:
                break

            job = Job.deserialize(job_json_string)
            job.status = JobStatus.RUNNING
            rv.append(job)

        return rv
585098
def get(*args)
      if args.size == 1 && args[0].is_a?(Hash)
        queue_name = (args[0][:name] || args[0]['name']).to_s
        queue_name.empty? ? super : queues_get(queue_name)
      else
        super
      end
    end
1146073
def get_all_queues(self, prefix=''):
        
        params = {}
        if prefix:
            params['QueueNamePrefix'] = prefix
        return self.get_list('ListQueues', params, [('QueueUrl', Queue)])
1109267
def filter_connection_params(queue_params):
    
    CONNECTION_PARAMS = ('URL', 'DB', 'USE_REDIS_CACHE',
                         'UNIX_SOCKET_PATH', 'HOST', 'PORT', 'PASSWORD',
                         'SENTINELS', 'MASTER_NAME', 'SOCKET_TIMEOUT',
                         'SSL', 'CONNECTION_KWARGS',)

    #return {p:v for p,v in queue_params.items() if p in CONNECTION_PARAMS}
    # Dict comprehension compatible with python 2.6
    return dict((p,v) for (p,v) in queue_params.items() if p in CONNECTION_PARAMS)
1133960
def all_known(cls, sources=None, prefixes=None):
        

        sources = sources or ("config", "jobs", "raw_subqueues")

        queues = set()

        if "config" in sources and not prefixes:
            # Some queues are explicitly declared in the config (including all root raw queues)
            cfg = context.get_current_config()

            queues_from_config = [
                t.get("queue")
                for t in (cfg.get("tasks") or {}).values()
                if t.get("queue")
            ]

            queues_from_config += Queue.get_queues_config().keys()

            queues_from_config += [
                t.get("retry_queue")
                for t in Queue.get_queues_config().values()
                if t.get("retry_queue")
            ]

            queues |= set(queues_from_config)

        if "jobs" in sources:

            # This will get all queues from mongodb, including those where we have only non-queued jobs
            for q in context.connections.mongodb_jobs.mrq_jobs.distinct("queue"):
                if prefixes and not any(q.startswith(p) for p in prefixes):
                    continue
                queues.add(q)

        if "raw_subqueues" in sources:
            for q in Queue.get_queues_config():
                if prefixes and not any(q + "/" == p for p in prefixes):
                    continue
                queue_obj = Queue(q)
                if queue_obj.is_raw and queue_obj.has_subqueues:
                    # TODO: optimize this with a single SUNION on all keys
                    queues |= queue_obj.get_known_subqueues()

        return queues
1265710
def queues(self, page=None, per_page=None, previous=None, prefix=None):
        
        options = {}
        if page is not None:
            raise Exception('page param is deprecated!')
        if per_page is not None:
            options['per_page'] = per_page
        if previous is not None:
            options['previous'] = previous
        if prefix is not None:
            options['prefix'] = prefix

        query = urlencode(options)
        url = 'queues'
        if query != '':
            url = "%s?%s" % (url, query)
        result = self.client.get(url)

        return [queue['name'] for queue in result['body']['queues']]
1233516
def get_queue_attributes(queue_url, attributes = ["All"])
      attributes = attributes.map(&:to_s)

      query = Hash[*attributes.each_with_index.map do |attribute, index|
        ["AttributeName.#{index+1}", attribute]
      end.flatten]

      action("GetQueueAttributes", queue_url, query)
    end
906412
def _generate_queues(queues, exchange, platform_queue):
        
        return set([
            Queue('celery', exchange, routing_key='celery'),
            Queue(platform_queue, exchange, routing_key='#'),
        ] + [
            Queue(q_name, exchange, routing_key=q_name)
            for q_name in queues
        ])
548721
def queue(self):
        """"""
        if not self.include_rq:
            return None
        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, 'redislite_queue'):
                ctx.redislite_queue = {}

                for queue_name in self.queues:
                    ctx.redislite_queue[queue_name] = \
                        Queue(queue_name, connection=self.connection)

            return ctx.redislite_queue
296436
def queuestats(self):
        

        start_time = time.time()
        log.debug("Starting queue stats...")

        # Fetch all known queues
        queues = [Queue(q) for q in Queue.all_known()]

        new_queues = {queue.id for queue in queues}
        old_queues = set(self.queue_etas.keys())

        for deleted_queue in old_queues.difference(new_queues):
            self.queue_etas.pop(deleted_queue)

        t = time.time()
        stats = {}

        for queue in queues:
            cnt = queue.count_jobs_to_dequeue()
            eta = self.queue_etas[queue.id].next(cnt, t=t)

            # Number of jobs to dequeue, ETA, Time of stats
            stats[queue.id] = "%d %s %d" % (cnt, eta if eta is not None else "N", int(t))

        with connections.redis.pipeline(transaction=True) as pipe:
            if random.randint(0, 100) == 0 or len(stats) == 0:
                pipe.delete(self.redis_queuestats_key)
            if len(stats) > 0:
                pipe.hmset(self.redis_queuestats_key, stats)
            pipe.execute()

        log.debug("... done queue stats in %0.4fs" % (time.time() - start_time))
750916
def __GetInstances(self, group_name = None, state_filter=None):
    
    all_instances = self.ec2.get_all_instances()
    instances = []
    for res in all_instances:
      for group in res.groups:
        if group_name and group.name != group_name:
          continue
        for instance in res.instances:
          if state_filter == None or instance.state == state_filter:
            instances.append(instance)
    return instances
1342668
def _list_queues():
    '''
    
    '''
    queue_dir = __opts__['sqlite_queue_dir']
    files = os.path.join(queue_dir, '*.db')
    paths = glob.glob(files)
    queues = [os.path.splitext(os.path.basename(item))[0] for item in paths]

    return queues
493811
def dump_queue(self, *names):
        
        conn = redis.StrictRedis(connection_pool=self.pool)
        for name in names:
            if name == 'worker':
                logger.debug('last worker: ' + conn.get(self._key_worker()))
            elif name == 'available':
                logger.debug('available: ' +
                             str(conn.zrevrange(self._key_available(), 0, -1,
                                                withscores=True)))
            elif name == 'priorities':
                logger.debug('priorities: ' +
                             str(conn.hgetall(self._key_priorities())))
            elif name == 'expiration':
                logger.debug('expiration: ' +
                             str(conn.zrevrange(self._key_expiration(), 0, -1,
                                                withscores=True)))
            elif name == 'workers':
                logger.debug('workers: ' +
                             str(conn.hgetall(self._key_workers())))
            elif name.startswith('reservations_'):
                item = name[len('reservations_'):]
                logger.debug('reservations for ' + item + ': ' +
                             str(conn.smembers(self._key_reservations(item))))
54377
def _queue_job(redis, queue_name, delegate, *args):
        
        log.info('Queuing job...')
        with Connection(redis):
            q = Queue(queue_name)
            job = q.enqueue(delegate, *args)
            return job.id