Skip to content
Snippets Groups Projects
Commit a04033f4 authored by Haibo Huang's avatar Haibo Huang Committed by android-build-merger
Browse files

[Updater] Rate limit updates

am: 11c4a759

Change-Id: Ie93f3f84f926008dcf42a7cf6cff1eee9328cbac
parents c4fbebee 11c4a759
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ python_binary_host {
name: "external_updater_notifier",
main: "notifier.py",
srcs: [
"git_utils.py",
"notifier.py",
],
}
......
......@@ -21,6 +21,7 @@ external_updater_notifier \
googletest
"""
from datetime import timedelta, datetime
import argparse
import json
import os
......@@ -28,6 +29,7 @@ import re
import subprocess
import time
import git_utils
def parse_args():
"""Parses commandline arguments."""
......@@ -73,6 +75,22 @@ def _send_email(proj, latest_ver, recipient, upgrade_log):
input=msg, encoding='ascii')
NOTIFIED_TIME_KEY_NAME = 'latest_notified_time'
def _should_notify(latest_ver, proj_history):
if latest_ver in proj_history:
# Processed this version before.
return False
timestamp = proj_history.get(NOTIFIED_TIME_KEY_NAME, 0)
time_diff = datetime.today() - datetime.fromtimestamp(timestamp)
if git_utils.is_commit(latest_ver) and time_diff <= timedelta(days=30):
return False
return True
def _process_results(args, history, results):
for proj, res in results.items():
if 'latest' not in res:
......@@ -82,11 +100,12 @@ def _process_results(args, history, results):
if latest_ver == current_ver:
continue
proj_history = history.setdefault(proj, {})
if latest_ver not in proj_history:
if _should_notify(latest_ver, proj_history):
upgrade_log = _upgrade(proj) if args.generate_change else ""
try:
_send_email(proj, latest_ver, args.recipients, upgrade_log)
proj_history[latest_ver] = int(time.time())
proj_history[NOTIFIED_TIME_KEY_NAME] = int(time.time())
except subprocess.CalledProcessError as err:
msg = """Failed to send email for {} ({}).
stdout: {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment