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, qname, tenant_uuid=None): tenant_uuid = tenant_uuid or self.default_tenant.uuid q = StatQueue(name=qname, tenant_uuid=tenant_uuid) self.add_me(q) return q.name, q.id
def _insert_queue(self, qname): q = StatQueue(name=qname) self.session.begin() self.session.add(q) self.session.commit() return q.name, q.id
def _insert_queue_to_stat_queue(self, queue_name=None): queue_name = queue_name if queue_name else 'test_queue' queue = StatQueue() queue.name = queue_name self.add_me(queue) return queue.name, queue.id
def _insert_queue_to_stat_queue(self, tenant_uuid=None): queue = StatQueue() queue.name = 'test_queue' queue.tenant_uuid = tenant_uuid or self.default_tenant.uuid self.add_me(queue) return queue.name, queue.id
def insert_stat_queue(self, **kwargs): session = self.Session() queue_id = kwargs['id'] query = session.query(StatQueue).filter(StatQueue.id == queue_id) if not query.count() > 0: queue = StatQueue(**kwargs) session.add(queue) session.commit()
def _insert_queue_to_stat_queue(self): queue = StatQueue() queue.name = 'test_queue' self.session.begin() self.session.add(queue) self.session.commit() return queue.name, queue.id
def _insert_queue(self, name): queue = StatQueue() queue.name = name self.session.begin() self.session.add(queue) self.session.commit() return queue
def insert_if_missing(session, all_queues): all_queues = set(all_queues) old_queues = set(r[0] for r in session.query(distinct(StatQueue.name))) missing_queues = list(all_queues - old_queues) for queue_name in missing_queues: new_queue = StatQueue() new_queue.name = queue_name session.add(new_queue)
def setUp(self): DAOTestCase.setUp(self) self._create_functions() self.callid_found = '1404377805.6457' event = QueueLog( time=t(2020, 1, 1, 0, 0, 0, tzinfo=pytz.UTC), callid=self.callid_found, queuename='found_queue', event='LEAVEEMPTY', ) self.add_me(event) event = QueueLog( time=t(2020, 1, 1, 0, 0, 0, tzinfo=pytz.UTC), callid=self.callid_found, queuename='found_queue', event='ENTERQUEUE', ) self.add_me(event) queue = StatQueue(name='found_queue', tenant_uuid=self.default_tenant.uuid) self.add_me(queue) self.callid_ignored = '1000000000.0000' event = QueueLog( time=t(2020, 2, 1, tzinfo=pytz.UTC), callid=self.callid_ignored, queuename='ignored_queue', event='LEAVEEMPTY', ) self.add_me(event) event = QueueLog( time=t(2020, 2, 1, tzinfo=pytz.UTC), callid=self.callid_ignored, queuename='ignored_queue', event='ENTERQUEUE', ) self.add_me(event) queue = StatQueue(name='ignored_queue', tenant_uuid=self.default_tenant.uuid) self.add_me(queue)
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