示例#1
0
def _create_missing_queues(session, queuelog_queues, confd_queues_by_name,
                           master_tenant):
    new_queue_names = set(confd_queues_by_name.keys())
    db_queue_query = session.query(StatQueue).filter(
        StatQueue.deleted.is_(False))
    old_queue_names = set(queue.name for queue in db_queue_query.all())
    missing_queues = list(new_queue_names - old_queue_names)
    for queue_name in missing_queues:
        queue = confd_queues_by_name[queue_name]
        new_queue = StatQueue()
        new_queue.name = queue_name
        new_queue.tenant_uuid = queue['tenant_uuid']
        new_queue.queue_id = queue['id']
        new_queue.deleted = False
        session.add(new_queue)
        session.flush()

    db_queue_query = session.query(StatQueue).filter(
        StatQueue.deleted.is_(True))
    old_queue_names = set(queue.name for queue in db_queue_query.all())
    missing_queues = list(
        set(queuelog_queues) - old_queue_names - new_queue_names)
    for queue_name in missing_queues:
        new_queue = StatQueue()
        new_queue.name = queue_name
        new_queue.tenant_uuid = master_tenant
        new_queue.deleted = True
        session.add(new_queue)
        session.flush()
    def _insert_queue(self,
                      name,
                      tenant_uuid=None,
                      queue_id=None,
                      deleted=False):
        queue = StatQueue()
        queue.name = name
        queue.tenant_uuid = tenant_uuid or self.default_tenant.uuid
        queue.queue_id = queue_id
        queue.deleted = deleted

        self.add_me(queue)

        return queue