Ejemplo n.º 1
0
    def test_should_return_empty_array_when_exception(self):
        # Given
        client = MagicMock()
        client.lrange = MagicMock()
        client.lrange.side_effect = redis.exceptions.RedisError

        # When
        result = get_venue_providers(client=client)

        # Then
        assert result == []
Ejemplo n.º 2
0
def batch_indexing_offers_in_algolia_by_venue_provider(client: Redis) -> None:
    venue_providers = get_venue_providers(client=client)

    if len(venue_providers) > 0:
        delete_venue_providers(client=client)
        for venue_provider in venue_providers:
            venue_provider_id = venue_provider["id"]
            provider_id = venue_provider["providerId"]
            venue_id = int(venue_provider["venueId"])
            _process_venue_provider(client=client,
                                    provider_id=provider_id,
                                    venue_id=venue_id,
                                    venue_provider_id=venue_provider_id)
Ejemplo n.º 3
0
    def test_should_return_venue_providers(self):
        # Given
        client = MagicMock()
        client.lrange = MagicMock()
        client.lrange.return_value = [
            '{"id": 1, "providerId": 2, "venueId": 3}',
            '{"id": 2, "providerId": 7, "venueId": 9}',
        ]

        # When
        result = get_venue_providers(client=client)

        # Then
        client.lrange.assert_called_once_with("venue_providers", 0, 2)
        assert result == [{"id": 1, "providerId": 2, "venueId": 3}, {"id": 2, "providerId": 7, "venueId": 9}]
Ejemplo n.º 4
0
def process_multi_indexing(client: Redis) -> None:
    venue_providers_to_process = get_venue_providers(client=client)
    delete_venue_providers(client=client)
    sync_worker_pool = settings.ALGOLIA_SYNC_WORKERS_POOL_SIZE

    while len(venue_providers_to_process) > 0:
        venue_provider = venue_providers_to_process[0]
        venue_providers_currently_in_sync = get_number_of_venue_providers_currently_in_sync(
            client=client)
        has_remaining_slot_in_pool = sync_worker_pool - venue_providers_currently_in_sync > 0

        if has_remaining_slot_in_pool:
            venue_providers_to_process.pop(0)
            _run_indexing(client=client, venue_provider=venue_provider)
        else:
            sleep(ALGOLIA_WAIT_TIME_FOR_AVAILABLE_WORKER)