Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Batch 8] Porting Notebook PRs #106

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ def content_security_policy(self):
def update_api_activity(self):
"""Update last_activity of API requests"""
# record activity of authenticated requests
if self._track_activity and getattr(self, '_user_cache', None):
if (
self._track_activity
and getattr(self, '_user_cache', None)
and self.get_argument('no_track_activity', None) is None
):
self.settings['api_last_activity'] = utcnow()

def finish(self, *args, **kwargs):
Expand Down
19 changes: 17 additions & 2 deletions jupyter_server/services/api/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test the basic /api endpoints"""

import requests
from datetime import timedelta

from jupyter_server._tz import isoformat
from jupyter_server._tz import isoformat, utcnow
from jupyter_server.utils import url_path_join
from jupyter_server.tests.launchserver import ServerTestBase

Expand Down Expand Up @@ -30,3 +30,18 @@ def test_get_status(self):
assert data['last_activity'].endswith('Z')
assert data['started'].endswith('Z')
assert data['started'] == isoformat(self.server.web_app.settings['started'])

def test_no_track_activity(self):
# initialize with old last api activity
old = utcnow() - timedelta(days=1)
settings = self.server.web_app.settings
settings['api_last_activity'] = old
# accessing status doesn't update activity
self.get('status')
assert settings['api_last_activity'] == old
# accessing with ?no_track_activity doesn't update activity
self.get('contents?no_track_activity=1')
assert settings['api_last_activity'] == old
# accessing without ?no_track_activity does update activity
self.get('contents')
assert settings['api_last_activity'] > old
7 changes: 6 additions & 1 deletion jupyter_server/services/contents/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ def increment_filename(self, filename, path='', insert=''):
"""
# Extract the full suffix from the filename (e.g. .tar.gz)
path = path.strip('/')
basename, dot, ext = filename.partition('.')
basename, dot, ext = filename.rpartition('.')
if ext != 'ipynb':
basename, dot, ext = filename.partition('.')

suffix = dot + ext

for i in itertools.count():
Expand Down Expand Up @@ -425,6 +428,8 @@ def copy(self, from_path, to_path=None):

If to_path not specified, it will be the parent directory of from_path.
If to_path is a directory, filename will increment `from_path-Copy#.ext`.
Considering multi-part extensions, the Copy# part will be placed before the first dot for all the extensions except `ipynb`.
For easier manual searching in case of notebooks, the Copy# part will be placed before the last dot.

from_path must be a full path to a file.
"""
Expand Down
1 change: 0 additions & 1 deletion jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def shutdown_kernel(self, kernel_id, now=False):
kernel._activity_stream = None
self.stop_buffering(kernel_id)
self._kernel_connections.pop(kernel_id, None)
self.last_kernel_activity = utcnow()

# Decrease the metric of number of kernels
# running for the relevant kernel type by 1
Expand Down