Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Docker entrypoint, rate limits and logs #69

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# DEPLOY
# =====

FROM ubuntu:22.04 as deploystep

Check warning on line 24 in Dockerfile

View workflow job for this annotation

GitHub Actions / build / docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
LABEL maintainer="Richard Bullington-McGuire <[email protected]>"

RUN apt-get update \
Expand All @@ -39,11 +39,13 @@

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

WORKDIR /app

CMD ['freezing-sync']
CMD ["/bin/sh", "-c", "freezing-sync"]
7 changes: 7 additions & 0 deletions freezing/sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Activity id=13209828474 name=None>"
# Silence it except for CRITICAL messages.

logging.getLogger("stravalib.attributes").setLevel(logging.CRITICAL)


statsd = DogStatsd(host=config.DATADOG_HOST, port=config.DATADOG_PORT)
6 changes: 6 additions & 0 deletions freezing/sync/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading