Open MartinKalema opened 1 month ago
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Hi @MartinKalema Thanks for the implementation I see code makes numerous API calls, which may hit rate limits. how about rate limiting or caching e.g through CC: @Baalmart
from ratelimit import limits, sleep_and_retry
import time
ONE_MINUTE = 60
@sleep_and_retry
@limits(calls=30, period=ONE_MINUTE)
def limited_api_call(api_function, *args, **kwargs):
return api_function(*args, **kwargs)
Hi @MartinKalema Thanks for the implementation I see code makes numerous API calls, which may hit rate limits. how about rate limiting or caching e.g through CC: @Baalmart
from ratelimit import limits, sleep_and_retry import time ONE_MINUTE = 60 @sleep_and_retry @limits(calls=30, period=ONE_MINUTE) def limited_api_call(api_function, *args, **kwargs): return api_function(*args, **kwargs)
Thank you @AnthonyByansi.
Could also be nice to think through what happens if the api call fails for whatever reason even after the retries.
Best,
Hi @MartinKalema Thanks for the implementation I see code makes numerous API calls, which may hit rate limits. how about rate limiting or caching e.g through CC: @Baalmart
from ratelimit import limits, sleep_and_retry import time ONE_MINUTE = 60 @sleep_and_retry @limits(calls=30, period=ONE_MINUTE) def limited_api_call(api_function, *args, **kwargs): return api_function(*args, **kwargs)
Thank you @AnthonyByansi.
Could also be nice to think through what happens if the api call fails for whatever reason even after the retries.
Best,
Hi @NicholasTurner23 Sure, how about we handle the failure gracefully;
error handling and logging: using logging module to log errors and capture exceptions. provide error messages and possibly fallback data or retry
retry with fallback: If all retries fail, log the error and proceed with default values.
import logging
logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', handlers=[logging.StreamHandler()] ) logger = logging.getLogger(name)
Happy to step in and give a hand where need be, cheers! π₯
CC: @MartinKalema / @Baalmart
Hi @MartinKalema Thanks for the implementation I see code makes numerous API calls, which may hit rate limits. how about rate limiting or caching e.g through CC: @Baalmart
from ratelimit import limits, sleep_and_retry import time ONE_MINUTE = 60 @sleep_and_retry @limits(calls=30, period=ONE_MINUTE) def limited_api_call(api_function, *args, **kwargs): return api_function(*args, **kwargs)
Thank you @AnthonyByansi. Could also be nice to think through what happens if the api call fails for whatever reason even after the retries. Best,
Hi @NicholasTurner23 Sure, how about we handle the failure gracefully;
- error handling and logging: using logging module to log errors and capture exceptions. provide error messages and possibly fallback data or retry
- retry with fallback: If all retries fail, log the error and proceed with default values.
import logging logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', handlers=[logging.StreamHandler()] ) logger = logging.getLogger(__name__)
Happy to step in and give a hand where need be, cheers! π₯ CC: @MartinKalema / @Baalmart
Thanks for the feedback @AnthonyByansi . The Weather API allows for 60 API calls per minute & @Mnoble-19 already implemented rate limiting within the OpenWeatherAPI class. The limit was set to 50.
WHAT DOES THIS PR DO?
Realtime-Low-Cost-Measurements
pipeline to integrate the OpenWeatherMap API.WHAT ISSUES ARE RELATED TO THIS PR?
JIRA CARDS
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Improvements
get_thingspeak_read_keys
function.Bug Fixes
Documentation