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

Side by Side Diff: appengine/swarming/server/bot_management.py

Issue 2661173004: Make deleted bots still show up when searched for by id (Closed)
Patch Set: Don't forget MP stuff Created 3 years, 10 months 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 unified diff | Download patch
OLDNEW
1 # Copyright 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Swarming bot management, e.g. list of known bots and their state. 5 """Swarming bot management, e.g. list of known bots and their state.
6 6
7 +---------+ 7 +---------+
8 |BotRoot | 8 |BotRoot |
9 |id=bot_id| 9 |id=bot_id|
10 +---------+ 10 +---------+
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 # Avoid having huge amounts of indices to query by quarantined/idle 154 # Avoid having huge amounts of indices to query by quarantined/idle
155 composite = ndb.ComputedProperty(lambda self: self._calc_composite(), 155 composite = ndb.ComputedProperty(lambda self: self._calc_composite(),
156 repeated=True) 156 repeated=True)
157 157
158 def _calc_composite(self): 158 def _calc_composite(self):
159 return [ 159 return [
160 self.QUARANTINED if self.quarantined else self.NOT_QUARANTINED, 160 self.QUARANTINED if self.quarantined else self.NOT_QUARANTINED,
161 self.BUSY if self.task_id else self.NOT_BUSY 161 self.BUSY if self.task_id else self.NOT_BUSY
162 ] 162 ]
163 163
164 # Was the bot deleted.
M-A Ruel 2017/01/31 18:45:04 Don't make it a BooleanProperty, as it implies tha
kjlubick 2017/01/31 19:04:40 done.
165 deleted = ndb.BooleanProperty(default=False)
166
164 @property 167 @property
165 def id(self): 168 def id(self):
166 return self.key.parent().string_id() 169 return self.key.parent().string_id()
167 170
168 def is_dead(self, now): 171 def is_dead(self, now):
169 """Returns True if the bot is dead based on timestamp now.""" 172 """Returns True if the bot is dead based on timestamp now."""
170 timeout = config.settings().bot_death_timeout_secs 173 timeout = config.settings().bot_death_timeout_secs
171 return (now - self.last_seen_ts).total_seconds() >= timeout 174 return (now - self.last_seen_ts).total_seconds() >= timeout
172 175
173 def to_dict(self, exclude=None): 176 def to_dict(self, exclude=None):
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 Returns: 446 Returns:
444 Tuple (True to restart, text message explaining the reason). 447 Tuple (True to restart, text message explaining the reason).
445 """ 448 """
446 # Periodically reboot bots to workaround OS level leaks (especially on Win). 449 # Periodically reboot bots to workaround OS level leaks (especially on Win).
447 running_time = state.get('running_time', 0) 450 running_time = state.get('running_time', 0)
448 assert isinstance(running_time, (int, float)) 451 assert isinstance(running_time, (int, float))
449 period = get_bot_reboot_period(bot_id, state) 452 period = get_bot_reboot_period(bot_id, state)
450 if period and running_time > period: 453 if period and running_time > period:
451 return True, 'Periodic reboot: running longer than %ds' % period 454 return True, 'Periodic reboot: running longer than %ds' % period
452 return False, '' 455 return False, ''
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698