Skip to content

Commit 234a192

Browse files
authored
Merge pull request #473 from sdmichelini/issue-471
feat: Allow Skipping of Activity Reporting
2 parents 66b21f0 + e538f4a commit 234a192

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

docs/source/server-process.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ One of:
157157
- A callable that takes any {ref}`callable arguments <server-process:callable-arguments>`,
158158
and returns a dictionary of strings that are used & treated same as above.
159159

160+
### `update_last_activity`
161+
162+
Whether to report activity from the proxy to Jupyter Server. If _True_, Jupyter Server
163+
will be notified of new activity. This is primarily used by JupyterHub for idle detection and culling.
164+
165+
Useful if you want to have a seperate way of determining activity through a
166+
proxied application.
167+
168+
Defaults to _True_.
169+
160170
(server-process:callable-arguments)=
161171

162172
#### Callable arguments

jupyter_server_proxy/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Traitlets based configuration for jupyter_server_proxy
33
"""
4+
45
import sys
56
from collections import namedtuple
67
from warnings import warn
@@ -41,6 +42,7 @@
4142
"new_browser_tab",
4243
"request_headers_override",
4344
"rewrite_response",
45+
"update_last_activity",
4446
],
4547
)
4648

@@ -56,6 +58,7 @@ def __init__(self, *args, **kwargs):
5658
self.unix_socket = sp.unix_socket
5759
self.mappath = sp.mappath
5860
self.rewrite_response = sp.rewrite_response
61+
self.update_last_activity = sp.update_last_activity
5962

6063
def get_request_headers_override(self):
6164
return self._realize_rendered_template(sp.request_headers_override)
@@ -80,6 +83,7 @@ def __init__(self, *args, **kwargs):
8083
self.requested_unix_socket = sp.unix_socket
8184
self.mappath = sp.mappath
8285
self.rewrite_response = sp.rewrite_response
86+
self.update_last_activity = sp.update_last_activity
8387

8488
def get_env(self):
8589
return self._realize_rendered_template(sp.environment)
@@ -162,6 +166,9 @@ def make_server_process(name, server_process_config, serverproxy_config):
162166
"rewrite_response",
163167
tuple(),
164168
),
169+
update_last_activity=server_process_config.get(
170+
"update_last_activity", True
171+
),
165172
)
166173

167174

@@ -282,6 +289,9 @@ def cats_only(response, path):
282289
instead of "dogs not allowed".
283290
284291
Defaults to the empty tuple ``tuple()``.
292+
293+
update_last_activity
294+
Will cause the proxy to report activity back to jupyter server.
285295
""",
286296
config=True,
287297
)

jupyter_server_proxy/handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(self, *args, **kwargs):
117117
tuple(),
118118
)
119119
self._requested_subprotocols = None
120+
self.update_last_activity = kwargs.pop("update_last_activity", True)
120121
super().__init__(*args, **kwargs)
121122

122123
# Support/use jupyter_server config arguments allow_origin and allow_origin_pat
@@ -234,7 +235,8 @@ def _record_activity(self):
234235
avoids proxied traffic being ignored by the notebook's
235236
internal idle-shutdown mechanism
236237
"""
237-
self.settings["api_last_activity"] = utcnow()
238+
if self.update_last_activity:
239+
self.settings["api_last_activity"] = utcnow()
238240

239241
def _get_context_path(self, host, port):
240242
"""

0 commit comments

Comments
 (0)