Ejemplo n.º 1
0
    def wrapper(*args, **kwargs):
        start_time = time.time()
        logger.info(build_cron_log_message(name=func.__name__, status=CronStatus.STARTED))

        result = func(*args, **kwargs)

        end_time = time.time()
        duration = end_time - start_time
        logger.info(build_cron_log_message(name=func.__name__, status=CronStatus.ENDED, duration=duration))
        return result
Ejemplo n.º 2
0
def synchronize_data_for_provider(provider_name: str, limit: Optional[int] = None) -> None:
    provider_class = get_local_provider_class_by_name(provider_name)
    try:
        provider = provider_class()
        do_update(provider, limit)
    except Exception:  # pylint: disable=broad-except
        logger.exception(build_cron_log_message(name=provider_name, status=CronStatus.FAILED))
Ejemplo n.º 3
0
    def test_should_contain_the_status(self):
        # When
        message = build_cron_log_message(name="generation_du_document_xml",
                                         status=CronStatus.STARTED)

        # Then
        assert "status=started" in message
Ejemplo n.º 4
0
    def test_should_contain_the_name(self):
        # When
        message = build_cron_log_message(name="generation_du_document_xml",
                                         status="")

        # Then
        assert "name=generation_du_document_xml" in message
Ejemplo n.º 5
0
    def wrapper(*args, **kwargs):
        start_time = time.time()
        logger.info(build_cron_log_message(name=func.__name__, status=CronStatus.STARTED))

        try:
            result = func(*args, **kwargs)
            db.session.commit()
            status = CronStatus.ENDED
        except Exception as exception:
            db.session.rollback()
            status = CronStatus.FAILED
            raise exception
        finally:
            duration = time.time() - start_time
            logger.info(build_cron_log_message(name=func.__name__, status=status, duration=duration))

        return result
Ejemplo n.º 6
0
def do_update(provider: LocalProvider, limit: Optional[int]):
    try:
        provider.updateObjects(limit)
    except Exception:  # pylint: disable=broad-except
        _remove_worker_id_after_venue_provider_sync_error(provider)
        logger.exception(
            build_cron_log_message(name=provider.__class__.__name__,
                                   status=CronStatus.STARTED))
Ejemplo n.º 7
0
    def test_should_contain_duration_field_when_given(self):
        # When
        message = build_cron_log_message(name="generation_du_document_xml",
                                         status=CronStatus.ENDED,
                                         duration=245)

        # Then
        assert "status=ended duration=245" in message
Ejemplo n.º 8
0
    def wrapper(*args, **kwargs):
        from pcapi.utils.logger import configure_json_logger

        configure_json_logger()
        start_time = time.time()
        logger.info(
            build_cron_log_message(name=func.__name__,
                                   status=CronStatus.STARTED))

        result = func(*args, **kwargs)

        end_time = time.time()
        duration = end_time - start_time
        logger.info(
            build_cron_log_message(name=func.__name__,
                                   status=CronStatus.ENDED,
                                   duration=duration))
        return result
Ejemplo n.º 9
0
def synchronize_venue_provider(venue_provider: VenueProvider,
                               limit: Optional[int] = None):
    provider_class = get_local_provider_class_by_name(
        venue_provider.provider.localClass)
    try:
        provider = provider_class(venue_provider)
        do_update(provider, limit)
    except Exception:  # pylint: disable=broad-except
        logger.exception(
            build_cron_log_message(name=provider_class.__name__,
                                   status=CronStatus.FAILED))
Ejemplo n.º 10
0
def synchronize_venue_provider(venue_provider: VenueProvider, limit: Optional[int] = None):
    if venue_provider.provider.implements_provider_api:
        synchronize_provider_api.synchronize_venue_provider(venue_provider)

    else:
        assert venue_provider.provider.localClass == "AllocineStocks", "Only AllocineStocks should reach this code"
        provider_class = get_local_provider_class_by_name(venue_provider.provider.localClass)

        logger.info(
            "Starting synchronization of venue_provider=%s with provider=%s",
            venue_provider.id,
            venue_provider.provider.localClass,
        )
        try:
            provider = provider_class(venue_provider)
            do_update(provider, limit)
        except Exception:  # pylint: disable=broad-except
            logger.exception(build_cron_log_message(name=provider_class.__name__, status=CronStatus.FAILED))
        logger.info(
            "Ended synchronization of venue_provider=%s with provider=%s",
            venue_provider.id,
            venue_provider.provider.localClass,
        )
Ejemplo n.º 11
0
def do_update(provider: LocalProvider, limit: Optional[int]):
    try:
        provider.updateObjects(limit)
    except Exception:  # pylint: disable=broad-except
        logger.exception(build_cron_log_message(name=provider.__class__.__name__, status=CronStatus.STARTED))
Ejemplo n.º 12
0
    def test_should_contain_the_log_type(self):
        # When
        message = build_cron_log_message(name="", status="")

        # Then
        assert "type=cron" in message