From f702cb39bbb623d41f48304e57c7233b00eb2853 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 31 Dec 2024 15:33:00 -0500 Subject: [PATCH 1/4] Fix Docker entrypoint --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1f8564b..3b53749 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,4 @@ ADD alembic.ini /app WORKDIR /app -CMD ['freezing-sync'] +CMD ["/bin/sh", "-c", "freezing-sync"] From 01b974ae39b101843a0913d51d6b34eadb616755 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 31 Dec 2024 15:55:17 -0500 Subject: [PATCH 2/4] Use latest freezing-model --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index de262fe..7536a11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ PyMySQL==1.1.1 colorlog==6.9.0 datadog==0.50.2 envparse==0.2.0 -freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.10.4.tar.gz +freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.11.2.tar.gz greenstalk==2.0.2 pytz==2024.2 requests==2.32.3 From eebc947410870adec065b8bf61f7da11223b71de Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 31 Dec 2024 16:32:14 -0500 Subject: [PATCH 3/4] Fend off rate limits, quiet noisy stravalib log stravalib.attributes throws useless WARNING messages constantly. SHut it up. Add a hacky delay between requests to avoid hitting Strava read rate limits. Until we upgrade to Stravalib 2.x this hopefully will tide us over. --- freezing/sync/config.py | 7 +++++++ freezing/sync/subscribe.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/freezing/sync/config.py b/freezing/sync/config.py index cc66e92..66d10ea 100644 --- a/freezing/sync/config.py +++ b/freezing/sync/config.py @@ -111,5 +111,12 @@ def init_logging(loglevel: int = logging.INFO, color: bool = False): else: l.setLevel(logging.INFO) + # This logger is very noisy and spits out WARNING level + # messages that are not very useful, such as: + # "WARNING [stravalib.attributes.EntityAttribute] Unable to set attribute visibility on entity " + # Silence it except for CRITICAL messages. + + logging.getLogger("stravalib.attributes").setLevel(logging.CRITICAL) + statsd = DogStatsd(host=config.DATADOG_HOST, port=config.DATADOG_PORT) diff --git a/freezing/sync/subscribe.py b/freezing/sync/subscribe.py index 4246774..e4f0585 100644 --- a/freezing/sync/subscribe.py +++ b/freezing/sync/subscribe.py @@ -25,6 +25,9 @@ def __init__( self.activity_sync = ActivitySync(self.logger) self.streams_sync = StreamSync(self.logger) + """Delay between requests to Strava API to avoid rate limiting.""" + self._THROTTLE_DELAY = 3.0 + def handle_message(self, message: ActivityUpdate): self.logger.info("Processing activity update {}".format(message)) @@ -102,6 +105,9 @@ def run_forever(self): ) # We put it back with a delay else: self.client.delete(job) + # FIXME: Work around stravalib 1.2's incomplete understanding of Strava Rate limits by just sleeping for a bit between requests. + sleep(_THROTTLE_DELAY) + except (KeyboardInterrupt, SystemExit): raise except: From 361c360c69aaf7f8f784a3f029b966e0dbf72f22 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 31 Dec 2024 16:40:09 -0500 Subject: [PATCH 4/4] Fix up installation of libraries --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3b53749..f21c4df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,9 @@ VOLUME /data COPY --from=buildstep /build/wheels /tmp/wheels -RUN pip3 install /tmp/wheels/* +# Thanks https://stackoverflow.com/a/74634740/424301 for the tip on +# using --use-deprecated=legacy-resolver +RUN pip3 install --use-deprecated=legacy-resolver /tmp/wheels/* RUN mkdir /app ADD alembic.ini /app