Skip to content

Commit

Permalink
Merge pull request #473 from sdmichelini/issue-471
Browse files Browse the repository at this point in the history
feat: Allow Skipping of Activity Reporting
  • Loading branch information
yuvipanda authored Jun 18, 2024
2 parents 66b21f0 + e538f4a commit 234a192
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/source/server-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ One of:
- A callable that takes any {ref}`callable arguments <server-process:callable-arguments>`,
and returns a dictionary of strings that are used & treated same as above.

### `update_last_activity`

Whether to report activity from the proxy to Jupyter Server. If _True_, Jupyter Server
will be notified of new activity. This is primarily used by JupyterHub for idle detection and culling.

Useful if you want to have a seperate way of determining activity through a
proxied application.

Defaults to _True_.

(server-process:callable-arguments)=

#### Callable arguments
Expand Down
10 changes: 10 additions & 0 deletions jupyter_server_proxy/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Traitlets based configuration for jupyter_server_proxy
"""

import sys
from collections import namedtuple
from warnings import warn
Expand Down Expand Up @@ -41,6 +42,7 @@
"new_browser_tab",
"request_headers_override",
"rewrite_response",
"update_last_activity",
],
)

Expand All @@ -56,6 +58,7 @@ def __init__(self, *args, **kwargs):
self.unix_socket = sp.unix_socket
self.mappath = sp.mappath
self.rewrite_response = sp.rewrite_response
self.update_last_activity = sp.update_last_activity

def get_request_headers_override(self):
return self._realize_rendered_template(sp.request_headers_override)
Expand All @@ -80,6 +83,7 @@ def __init__(self, *args, **kwargs):
self.requested_unix_socket = sp.unix_socket
self.mappath = sp.mappath
self.rewrite_response = sp.rewrite_response
self.update_last_activity = sp.update_last_activity

def get_env(self):
return self._realize_rendered_template(sp.environment)
Expand Down Expand Up @@ -162,6 +166,9 @@ def make_server_process(name, server_process_config, serverproxy_config):
"rewrite_response",
tuple(),
),
update_last_activity=server_process_config.get(
"update_last_activity", True
),
)


Expand Down Expand Up @@ -282,6 +289,9 @@ def cats_only(response, path):
instead of "dogs not allowed".
Defaults to the empty tuple ``tuple()``.
update_last_activity
Will cause the proxy to report activity back to jupyter server.
""",
config=True,
)
Expand Down
4 changes: 3 additions & 1 deletion jupyter_server_proxy/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(self, *args, **kwargs):
tuple(),
)
self._requested_subprotocols = None
self.update_last_activity = kwargs.pop("update_last_activity", True)
super().__init__(*args, **kwargs)

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

def _get_context_path(self, host, port):
"""
Expand Down

0 comments on commit 234a192

Please sign in to comment.