Skip to content

Commit 711f426

Browse files
ashokDevsclaude
andcommitted
perf: cache health check for 60s to stop hammering GitHub API
The health check was calling GitHub's verify_token_scopes on every request (~every 5s from Render), burning through rate limits for no reason. Now caches the result for 60 seconds. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8fc98a commit 711f426

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

backend/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,17 @@ def get_job_feed(job_id):
921921
}), 200
922922

923923

924+
_health_cache = {'result': None, 'expires': 0}
925+
924926
@app.route('/health', methods=['GET'])
925927
def health_check():
928+
import time
929+
now = time.time()
930+
931+
# Cache health check result for 60s to avoid hammering GitHub API
932+
if _health_cache['result'] and now < _health_cache['expires']:
933+
return jsonify(_health_cache['result']), 200
934+
926935
config = load_config()
927936

928937
checks = {
@@ -955,9 +964,9 @@ def health_check():
955964
if github_scopes:
956965
response['github_scopes'] = github_scopes
957966

958-
# Always return 200 for the liveness probe — external credential issues
959-
# should not prevent the service from being considered alive by the
960-
# load balancer / platform health check.
967+
_health_cache['result'] = response
968+
_health_cache['expires'] = now + 60
969+
961970
return jsonify(response), 200
962971

963972

0 commit comments

Comments
 (0)