Skip to content

Commit

Permalink
Make kernel_id as a conditional optional field (#1300)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
  • Loading branch information
allstrive and blink1073 committed Jul 13, 2023
1 parent 6658e2f commit 2563bae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
13 changes: 11 additions & 2 deletions jupyter_server/event_schemas/kernel_actions/v1.yaml
Expand Up @@ -7,7 +7,6 @@ description: |
type: object
required:
- action
- kernel_id
- msg
properties:
action:
Expand Down Expand Up @@ -39,7 +38,7 @@ properties:
description: |
Kernel id.
This is a required field.
This is a required field for all actions and statuses except action start with status error.
kernel_name:
type: string
description: |
Expand Down Expand Up @@ -69,3 +68,13 @@ properties:
type: string
description: |
Description of the event specified in action.
if:
not:
properties:
status:
const: error
action:
const: start
then:
required:
- kernel_id
23 changes: 13 additions & 10 deletions jupyter_server/services/kernels/kernelmanager.py
Expand Up @@ -738,28 +738,31 @@ async def wrapped_method(self, *args, **kwargs):
# If the method succeeds, emit a success event.
try:
out = await method(self, *args, **kwargs)
data = {
"kernel_name": self.kernel_name,
"action": action,
"status": "success",
"msg": success_msg.format(
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
),
}
if self.kernel_id:
data["kernel_id"] = self.kernel_id
self.emit(
schema_id="https://events.jupyter.org/jupyter_server/kernel_actions/v1",
data={
"kernel_id": self.kernel_id,
"kernel_name": self.kernel_name,
"action": action,
"status": "success",
"msg": success_msg.format(
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
),
},
data=data,
)
return out
# If the method fails, emit a failed event.
except Exception as err:
data = {
"kernel_id": self.kernel_id,
"kernel_name": self.kernel_name,
"action": action,
"status": "error",
"msg": str(err),
}
if self.kernel_id:
data["kernel_id"] = self.kernel_id
# If the exception is an HTTPError (usually via a gateway request)
# log the status_code and HTTPError log_message.
if isinstance(err, web.HTTPError):
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Expand Up @@ -277,6 +277,8 @@ filterwarnings = [
"ignore:datetime.utcnow:DeprecationWarning",
# from nbformat
"ignore:Importing ErrorTree directly from the jsonschema package:DeprecationWarning",
# From jupyter_events
"module:jsonschema.RefResolver is deprecated as of:DeprecationWarning",
# ignore pytest warnings.
"ignore:::_pytest",
]
Expand Down

0 comments on commit 2563bae

Please sign in to comment.