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

Allow configuring timeout #1

Merged
merged 2 commits into from
Sep 20, 2023
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY apolpi.py boot.sh ./
RUN chmod +x boot.sh

ENV FLASK_APP apolpi.py
ENV TIMEOUT 30
EXPOSE 80

ENTRYPOINT ["/apolpi/boot.sh"]
4 changes: 3 additions & 1 deletion apolpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

global CACHED_RESULT
global CACHED_TIME
global TIMEOUT
CACHED_RESULT = None
CACHED_TIME = 0
TIMEOUT = int(os.environ.get('TIMEOUT', 30))

app = Flask(__name__)

Expand Down Expand Up @@ -113,7 +115,7 @@ def doit():
global CACHED_TIME
global CACHED_RESULT
now = time.time()
if now - CACHED_TIME > 30:
if now - CACHED_TIME > TIMEOUT:
CACHED_RESULT = _fetch()
CACHED_TIME = now

Expand Down
Loading