Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: scheduler/monitor_db_cleanup.py

Issue 4823005: Merge remote branch 'cros/upstream' into tempbranch (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: patch Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scheduler/monitor_db.py ('k') | scheduler/monitor_db_cleanup_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scheduler/monitor_db_cleanup.py
diff --git a/scheduler/monitor_db_cleanup.py b/scheduler/monitor_db_cleanup.py
index 60b02f76ab2ebbd10b3c85413bd2fdc12e89fd81..d8bab116c6d145c647106780d5f0144269765ae9 100644
--- a/scheduler/monitor_db_cleanup.py
+++ b/scheduler/monitor_db_cleanup.py
@@ -3,7 +3,7 @@ Autotest AFE Cleanup used by the scheduler
"""
-import datetime, time, logging
+import datetime, time, logging, random
from autotest_lib.database import database_connection
from autotest_lib.frontend.afe import models
from autotest_lib.scheduler import email_manager, scheduler_config
@@ -162,6 +162,14 @@ class UserCleanup(PeriodicCleanup):
return (self._last_reverify_time + reverify_period_sec) <= time.time()
+ def _choose_subset_of_hosts_to_reverify(self, hosts):
+ """Given hosts needing verification, return a subset to reverify."""
+ max_at_once = scheduler_config.config.reverify_max_hosts_at_once
+ if (max_at_once > 0 and len(hosts) > max_at_once):
+ return random.sample(hosts, max_at_once)
+ return sorted(hosts)
+
+
def _reverify_dead_hosts(self):
if not self._should_reverify_hosts_now():
return
@@ -177,8 +185,11 @@ class UserCleanup(PeriodicCleanup):
if not hosts:
return
- logging.info('Reverifying dead hosts %s'
- % ', '.join(host.hostname for host in hosts))
+ hosts = list(hosts)
+ total_hosts = len(hosts)
+ hosts = self._choose_subset_of_hosts_to_reverify(hosts)
+ logging.info('Reverifying dead hosts (%d of %d) %s', len(hosts),
+ total_hosts, ', '.join(host.hostname for host in hosts))
for host in hosts:
models.SpecialTask.schedule_special_task(
host=host, task=models.SpecialTask.Task.VERIFY)
« no previous file with comments | « scheduler/monitor_db.py ('k') | scheduler/monitor_db_cleanup_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698