diff options
author | Haibo Huang <hhb@google.com> | 2019-01-31 16:09:55 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-01-31 16:09:55 -0800 |
commit | 5735b875c2e522a537226ef6fd66826377e1fe83 (patch) | |
tree | 5e6d7758f2cc9a1b0fbef0ff7c38cfa09a1f98d2 | |
parent | 65efaa622aa9c49dc770d80cebee80710a16d8b7 (diff) | |
parent | b0daf22251b6aa20556eb4cecc841ecf107ee397 (diff) | |
download | external_updater-5735b875c2e522a537226ef6fd66826377e1fe83.tar.gz |
[Updater] Rate limit updates am: 11c4a759d0 am: a04033f47d
am: b0daf22251
Change-Id: I1396be7691cd3fae8a633eeb9d3b2e1c6cfffc8b
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | notifier.py | 21 |
2 files changed, 21 insertions, 1 deletions
@@ -27,6 +27,7 @@ python_binary_host { name: "external_updater_notifier", main: "notifier.py", srcs: [ + "git_utils.py", "notifier.py", ], } diff --git a/notifier.py b/notifier.py index 982354c..1e2c7cd 100644 --- a/notifier.py +++ b/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: {} |