Exemplo n.º 1
0
    def __init__(self):
        """
        Initialize the indexing service
        """
        LOGGER.info('Starting indexing service')
        storage_engine = create_sql_engine(SqlEngineType.MYSQL,
                                           **config.storage)
        self._session_provider = SqlSessionProvider(storage_engine)
        self._source_service = SourceService(self._session_provider)
        self._new_service = NewService(self._session_provider)
        self._named_entity_service = NamedEntityService(self._session_provider)
        self._named_entity_type_service = NamedEntityTypeService(
            self._session_provider)
        self._noun_chunk_service = NounChunkService(self._session_provider)

        self._exchange_consumer = ExchangeConsumer(
            **config.rabbit,
            exchange='news',
            queue_name='news-indexing',
            message_callback=self.index_message,
            logger=LOGGER)

        if not self._exchange_consumer.test_connection():
            LOGGER.error('Error connecting to the queue provider. Exiting...')
            sys.exit(1)

        self._consume_process = None
        if platform.system() != 'Windows':
            LOGGER.info('Starting consumer process')
            self._consume_process = Process(
                target=self._exchange_consumer.__call__)
            self._consume_process.start()
 def __init__(self, name: str, event_api: str, event_name: str,
              storage_config: dict):
     super().__init__(name, event_api, event_name)
     storage_engine = create_sql_engine(SqlEngineType.MYSQL,
                                        **storage_config)
     self.session_provider = SqlSessionProvider(storage_engine)
     self.user_service = UserService(self.session_provider)
    def setUp(self) -> None:
        """
        Set up the test environment creating the database engine
        """
        container.reset()
        test_engine = create_sql_engine(SqlEngineType.SQLITE)
        self.session_provider = SqlSessionProvider(test_engine)
        BASE.query = self.session_provider.query_property
        init_sql_db(BASE, test_engine)

        named_entity_type_service = NamedEntityTypeService(session_provider=self.session_provider)
        named_entity_service = NamedEntityService(session_provider=self.session_provider)
        named_entity_type = asyncio.run(named_entity_type_service.save(name='TEST'))
        asyncio.run(named_entity_service.save(value=self.TEST_ENTITY_1, named_entity_type_id=named_entity_type.id))
        asyncio.run(named_entity_service.save(value=self.TEST_ENTITY_2, named_entity_type_id=named_entity_type.id))

        noun_chunks_service = NounChunkService(session_provider=self.session_provider)
        asyncio.run(noun_chunks_service.save(value=self.TEST_NOUN_CHUNK_1))
        asyncio.run(noun_chunks_service.save(value=self.TEST_NOUN_CHUNK_2))
        asyncio.run(noun_chunks_service.save(value=self.TEST_NOUN_CHUNK_3))

        self.newspaper_service = NewspaperService(session_provider=self.session_provider)

        app = Application()
        container.set('session_provider', self.session_provider)
        container.set('named_entity_service', named_entity_service)
        container.set('noun_chunk_service', noun_chunks_service)
        container.set('newspaper_service', self.newspaper_service)
        self.app = app
Exemplo n.º 4
0
 def setUp(self) -> None:
     """
     Set up the test environment creating the database engine
     """
     test_engine = create_sql_engine(SqlEngineType.SQLITE)
     self.session_provider = SqlSessionProvider(test_engine)
     BASE.query = self.session_provider.query_property
     init_sql_db(BASE, test_engine)
    def setUp(self) -> None:
        """
        Set up the test environment creating the database engine
        """
        container.reset()
        test_engine = create_sql_engine(SqlEngineType.SQLITE)
        self.session_provider = SqlSessionProvider(test_engine)
        BASE.query = self.session_provider.query_property
        init_sql_db(BASE, test_engine)

        self.user_service = UserService(session_provider=self.session_provider)
        self.source_service = SourceService(session_provider=self.session_provider)

        app = Application()
        container.set('session_provider', self.session_provider)
        container.set('source_service', self.source_service)
        container.set('user_service', self.user_service)
        self.app = app
    def setUp(self, consumer_mock, process_mock, create_engine_mock) -> None:
        container.reset()

        self.apm_mock = Mock(spec=Client)
        container.set('apm', self.apm_mock)
        self.consumer_mock = consumer_mock
        self.process_mock = process_mock
        self.app = Application()

        test_engine = create_sql_engine(SqlEngineType.SQLITE)
        init_sql_db(BASE, test_engine)
        self.session_provider = SqlSessionProvider(test_engine)

        create_engine_mock.return_value = test_engine

        self.source_service = SourceService(self.session_provider)
        self.news_service = NewService(self.session_provider)
        self.named_entity_service = NamedEntityService(self.session_provider)
        self.named_entity_type_service = NamedEntityTypeService(
            self.session_provider)
        self.index_service = IndexService()