forked from jupyter-server/jupyter_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jupyter-server#438 from kevin-bates/port-terminal-…
…culling Port terminal culling from Notebook
- Loading branch information
Showing
8 changed files
with
294 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,34 @@ | ||
import json | ||
from tornado import web | ||
from ..base.handlers import APIHandler | ||
from ..prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL | ||
|
||
|
||
|
||
class TerminalRootHandler(APIHandler): | ||
|
||
@web.authenticated | ||
def get(self): | ||
tm = self.terminal_manager | ||
terms = [{'name': name} for name in tm.terminals] | ||
self.finish(json.dumps(terms)) | ||
|
||
# Update the metric below to the length of the list 'terms' | ||
TERMINAL_CURRENTLY_RUNNING_TOTAL.set( | ||
len(terms) | ||
) | ||
models = self.terminal_manager.list() | ||
self.finish(json.dumps(models)) | ||
|
||
@web.authenticated | ||
def post(self): | ||
"""POST /terminals creates a new terminal and redirects to it""" | ||
data = self.get_json_body() or {} | ||
|
||
name, _ = self.terminal_manager.new_named_terminal(**data) | ||
self.finish(json.dumps({'name': name})) | ||
|
||
# Increase the metric by one because a new terminal was created | ||
TERMINAL_CURRENTLY_RUNNING_TOTAL.inc() | ||
model = self.terminal_manager.create(**data) | ||
self.finish(json.dumps(model)) | ||
|
||
|
||
class TerminalHandler(APIHandler): | ||
SUPPORTED_METHODS = ('GET', 'DELETE') | ||
|
||
@web.authenticated | ||
def get(self, name): | ||
tm = self.terminal_manager | ||
if name in tm.terminals: | ||
self.finish(json.dumps({'name': name})) | ||
else: | ||
raise web.HTTPError(404, "Terminal not found: %r" % name) | ||
model = self.terminal_manager.get(name) | ||
self.finish(json.dumps(model)) | ||
|
||
@web.authenticated | ||
async def delete(self, name): | ||
tm = self.terminal_manager | ||
if name in tm.terminals: | ||
await tm.terminate(name, force=True) | ||
self.set_status(204) | ||
self.finish() | ||
|
||
# Decrease the metric below by one | ||
# because a terminal has been shutdown | ||
TERMINAL_CURRENTLY_RUNNING_TOTAL.dec() | ||
|
||
else: | ||
raise web.HTTPError(404, "Terminal not found: %r" % name) | ||
await self.terminal_manager.terminate(name, force=True) | ||
self.set_status(204) | ||
self.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.