cull_idle_servers.py: rebind max_age and inactive_limit locally

- In the cull script, the max_age and inactive_limit are used from the
  outer scope.  In the case that you add extra logic, one may want to
  modify these values.
- In that case, you either have to rename them locally, or access the
  outer scope with "nonlocal", the first of which is too much work,
  the second of which has a high chance of introducing bugs (as it did
  for me).
- This change introduces a fix for everyone.  It doesn't change basic
  functionality, but makes local modifications simpler.
This commit is contained in:
Richard Darst
2019-10-25 14:36:16 +03:00
parent 2847c3a90c
commit 52c099193d

View File

@@ -117,7 +117,7 @@ def cull_idle(
futures = []
@coroutine
def handle_server(user, server_name, server):
def handle_server(user, server_name, server, max_age, inactive_limit):
"""Handle (maybe) culling a single server
"server" is the entire server model from the API.
@@ -252,7 +252,7 @@ def cull_idle(
'url': user['server'],
}
server_futures = [
handle_server(user, server_name, server)
handle_server(user, server_name, server, max_age, inactive_limit)
for server_name, server in servers.items()
]
results = yield multi(server_futures)