Skip to content

Commit

Permalink
Enforce the type of idle culler options
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgianaElena committed Jun 12, 2019
1 parent 5ec0467 commit 20374db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
25 changes: 10 additions & 15 deletions tljh/configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,22 @@ def update_traefik_api(c, config):
c.TraefikTomlProxy.traefik_api_password = config['traefik_api']['password']


def set_cull_idle_service(c, config):
def set_cull_idle_service(config):
"""
Set Idle Culler service
"""
cull_cmd = [
sys.executable, '/srv/src/tljh/cull_idle_servers.py'
]
if config['services']['cull']['timeout']:
cull_cmd.append('--timeout=%s' % config['services']['cull']['timeout'])
cull_config = config['services']['cull']
print()

if config['services']['cull']['every']:
cull_cmd.append('--cull-every=%s' % config['services']['cull']['every'])

if config['services']['cull']['concurrency']:
cull_cmd.append('--concurrency=%s' % config['services']['cull']['concurrency'])

if config['services']['cull']['users']:
cull_cmd.append('--cull-users')

if config['services']['cull']['max_age']:
cull_cmd.append('--max-age=%s' % config['services']['cull']['max_age'])
cull_cmd += ['--timeout=%d' % cull_config['timeout']]
cull_cmd += ['--cull-every=%d' % cull_config['every']]
cull_cmd += ['--concurrency=%d' % cull_config['concurrency']]
cull_cmd += ['--max-age=%d' % cull_config['max_age']]
if cull_config['users']:
cull_cmd += ['--cull-users']

cull_service = {
'name': 'cull-idle',
Expand All @@ -237,7 +232,7 @@ def set_cull_idle_service(c, config):
def update_services(c, config):
c.JupyterHub.services = []
if config['services']['cull']['enabled']:
c.JupyterHub.services.append(set_cull_idle_service(c, config))
c.JupyterHub.services.append(set_cull_idle_service(config))


def _merge_dictionaries(a, b, path=None, update=True):
Expand Down
10 changes: 5 additions & 5 deletions tljh/cull_idle_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,16 @@ def handle_user(user):
default=os.environ.get('JUPYTERHUB_API_URL'),
help="The JupyterHub API URL",
)
define('timeout', default=600, help="The idle timeout (in seconds)")
define('cull_every', default=0,
define('timeout', type=int, default=600, help="The idle timeout (in seconds)")
define('cull_every', type=int, default=0,
help="The interval (in seconds) for checking for idle servers to cull")
define('max_age', default=0,
define('max_age', type=int, default=0,
help="The maximum age (in seconds) of servers that should be culled even if they are active")
define('cull_users', default=False,
define('cull_users', type=bool, default=False,
help="""Cull users in addition to servers.
This is for use in temporary-user cases such as tmpnb.""",
)
define('concurrency', default=10,
define('concurrency', type=int, default=10,
help="""Limit the number of concurrent requests made to the Hub.
Deleting a lot of users at the same time can slow down the Hub,
Expand Down

0 comments on commit 20374db

Please sign in to comment.