hyperion/models/util.py
async def update_bikes(delta: Optional[timedelta] = None):
    """
    A background task that retrieves bike data.
    :param delta: The amount of time to wait between checks.
    """

    async def update(delta: timedelta):
        logger.info("Fetching bike data.")
        if await should_update_bikes(delta):
            try:
                bike_data = await fetch_bikes()
            except ApiError:
                logger.debug(f"Failed to fetch bikes.")
            except CircuitBreakerError:
                logger.debug(f"Failed to fetch bikes (circuit breaker open).")
            else:
                # save only bikes that aren't in the db
                most_recent_bike = Bike.get_most_recent_bike()
                new_bikes = (
                    Bike.from_dict(bike) for index, bike in enumerate(bike_data)
                    if index > (most_recent_bike.id if most_recent_bike is not None else -1)
                )

                counter = 0
                with Bike._meta.database.atomic():
                    for bike in new_bikes:
                        bike.save()
                        counter += 1
                logger.info(f"Saved {counter} new entries.")
        else:
            logger.info("Bike data up to date.")

    if delta is None:
        await update(timedelta(days=1000))
    else:
        while True:
            await update(delta)
            await asyncio.sleep(delta.total_seconds())
async def update_bikes(delta: Optional[timedelta] = None):
    """
    A background task that retrieves bike data.
    :param delta: The amount of time to wait between checks.
    """

    async def update(delta: timedelta):
        logger.info("Fetching bike data.")
        if await should_update_bikes(delta):
            try:
                bike_data = await fetch_bikes()
            except ApiError:
                logger.debug(f"Failed to fetch bikes.")
            except CircuitBreakerError:
                logger.debug(f"Failed to fetch bikes (circuit breaker open).")
            else:
                # save only bikes that aren't in the db
                most_recent_bike = Bike.get_most_recent_bike()
                new_bikes = (
                    Bike.from_dict(bike) for index, bike in enumerate(bike_data)
                    if index > (most_recent_bike.id if most_recent_bike is not None else -1)
                )

                counter = 0
                with Bike._meta.database.atomic():
                    for bike in new_bikes:
                        bike.save()
                        counter += 1
                logger.info(f"Saved {counter} new entries.")
        else:
            logger.info("Bike data up to date.")

    if delta is None:
        await update(timedelta(days=1000))
    else:
        while True:
            await update(delta)
            await asyncio.sleep(delta.total_seconds())
A background task that retrieves bike data.
    :param delta: The amount of time to wait between checks.