Skip to content

Commit 9212191

Browse files
authored
Merge pull request #74 from HCharlie/MLX-1204
add options to cull named servers and default servers separately
2 parents cc13b34 + a84e523 commit 9212191

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ python3 -m jupyterhub_idle_culler [--timeout=900] [--url=http://localhost:8081/h
135135
if --cull-users=true). (default True)
136136
--cull-every The interval (in seconds) for checking for
137137
idle servers to cull. (default 0)
138+
--cull-default-servers Whether default servers should be culled (only
139+
if --cull-default-servers=true). (default True)
140+
--cull-named-servers Whether named servers should be culled (only
141+
if --cull-named-servers=true). (default True)
138142
--cull-users Cull users in addition to servers. This is
139143
for use in temporary-user cases such as
140144
tmpnb. (default False)

jupyterhub_idle_culler/__init__.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ async def cull_idle(
8787
internal_certs_location="",
8888
cull_admin_users=True,
8989
api_page_size=0,
90+
cull_default_servers=True,
91+
cull_named_servers=True,
9092
):
9193
"""Shutdown idle single-user servers
9294
@@ -234,8 +236,16 @@ async def handle_server(user, server_name, server, max_age, inactive_limit):
234236
# return False
235237
# inactive_limit = server['state']['culltime']
236238

239+
is_default_server = server_name == ""
240+
is_named_server = server_name != ""
241+
237242
should_cull = (
238-
inactive is not None and inactive.total_seconds() >= inactive_limit
243+
inactive is not None
244+
and inactive.total_seconds() >= inactive_limit
245+
and (
246+
(cull_default_servers and is_default_server)
247+
or (cull_named_servers and is_named_server)
248+
)
239249
)
240250
if should_cull:
241251
app_log.info(
@@ -561,6 +571,26 @@ def main():
561571
"""
562572
).strip(),
563573
)
574+
define(
575+
"cull_default_servers",
576+
type=bool,
577+
default=True,
578+
help=dedent(
579+
"""
580+
Whether default servers should be culled (only if --cull-default-servers=true).
581+
"""
582+
).strip(),
583+
)
584+
define(
585+
"cull_named_servers",
586+
type=bool,
587+
default=True,
588+
help=dedent(
589+
"""
590+
Whether named servers should be culled (only if --cull-named-servers=true).
591+
"""
592+
).strip(),
593+
)
564594

565595
parse_command_line()
566596
if not options.cull_every:
@@ -589,6 +619,8 @@ def main():
589619
internal_certs_location=options.internal_certs_location,
590620
cull_admin_users=options.cull_admin_users,
591621
api_page_size=options.api_page_size,
622+
cull_default_servers=options.cull_default_servers,
623+
cull_named_servers=options.cull_named_servers,
592624
)
593625
# schedule first cull immediately
594626
# because PeriodicCallback doesn't start until the end of the first interval

0 commit comments

Comments
 (0)