Skip to content

Commit

Permalink
Merge pull request #1 from enolfc/fix-build
Browse files Browse the repository at this point in the history
Fix conditions for showing the notification
  • Loading branch information
enolfc authored Aug 29, 2024
2 parents 557dc5e + 9194f52 commit aa98daf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 58 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/check-release.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:
VALIDATE_ALL_CODEBASE: false
# Fail on errors
DISABLE_ERRORS: false
# this is already done by the other linting action
# and the tsconfig conflicts, so removing
VALIDATE_TYPESCRIPT_STANDARD: false
12 changes: 2 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.
<!-- <START NEW CHANGELOG ENTRY> -->

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- First implementation of a simple notification emiter whenever the resource
usage gets into warning
<!-- <END NEW CHANGELOG ENTRY> -->
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# notebooks-resource-warning

[![Github Actions Status](https://github.com/EGI-Federation/notebooks-resource-warnings/workflows/Build/badge.svg)](https://github.com/EGI-Federation/notebooks-resource-warnings/actions/workflows/build.yml)
[![Github Actions Status](https://github.com/EGI-Federation/notebooks-resource-warning/workflows/Build/badge.svg)](https://github.com/EGI-Federation/notebooks-resource-warning/actions/workflows/build.yml)

A JupyterLab extension that shows a notification whenever the usage of memory goes into `warn` status (as provided by the [Jupyter Resource Usage extension](https://github.com/jupyter-server/jupyter-resource-usage)
A JupyterLab extension that shows a notification whenever the usage of memory
goes into `warn` status (as provided by the
[Jupyter Resource Usage extension](https://github.com/jupyter-server/jupyter-resource-usage)

## Requirements

Expand Down Expand Up @@ -45,7 +47,9 @@ jupyter labextension develop . --overwrite
jlpm build
```

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
You can watch the source directory and run JupyterLab at the same time in
different terminals to watch for changes in the extension's source and
automatically rebuild the extension.

```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
Expand All @@ -54,9 +58,15 @@ jlpm watch
jupyter lab
```

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
With the watch command running, every saved change will immediately be built
locally and available in your running JupyterLab. Refresh JupyterLab to load the
change in your browser (you may need to wait several seconds for the extension
to be rebuilt).

By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
By default, the `jlpm build` command generates the source maps for this
extension to make it easier to debug using the browser dev tools. To also
generate source maps for the JupyterLab core extensions, you can run the
following command:

```bash
jupyter lab build --minimize=False
Expand All @@ -68,9 +78,11 @@ jupyter lab build --minimize=False
pip uninstall notebooks-resource-warning
```

In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
folder is located. Then you can remove the symlink named `resource_warning` within that folder.
In development mode, you will also need to remove the symlink created by
`jupyter labextension develop` command. To find its location, you can run
`jupyter labextension list` to figure out where the `labextensions` folder is
located. Then you can remove the symlink named `resource_warning` within that
folder.

### Packaging the extension

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"jupyterlab",
"jupyterlab-extension"
],
"homepage": "https://github.com/EGI-Federation/resource-warnings",
"homepage": "https://github.com/EGI-Federation/notebooks-resource-warning",
"bugs": {
"url": "https://github.com/EGI-Federation/resource-warnings/issues"
"url": "https://github.com/EGI-Federation/notebooks-resource-warning/issues"
},
"license": "BSD-3-Clause",
"author": {
Expand All @@ -26,7 +26,7 @@
"style": "style/index.css",
"repository": {
"type": "git",
"url": "https://github.com/EGI-Federation/resource-warnings.git"
"url": "https://github.com/EGI-Federation/notebooks-resource-warning.git"
},
"scripts": {
"build": "jlpm build:lib && jlpm build:labextension:dev",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
description: 'A JupyterLab extension.',
autoStart: true,
activate: async (app: JupyterFrontEnd) => {
let refreshRate = DEFAULT_REFRESH_RATE;
const refreshRate = DEFAULT_REFRESH_RATE;
const model = new ResourceUsage.Model({ refreshRate });
model.refresh();
}
Expand Down
14 changes: 8 additions & 6 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ export namespace ResourceUsage {
? Math.min(numBytes / memoryLimit, 1) * 100
: 0;
const memwarn = value.limits.memory?.warn;
if (memwarn && !this._previousWarn) {
this._previousWarn = true;
Notification.warning(
'Memory usage reached ' + memoryPercent.toFixed() + '%.',
{ autoClose: 3000 }
);
if (memwarn) {
if (!this._previousWarn) {
this._previousWarn = true;
Notification.warning(
'Memory usage reached ' + memoryPercent.toFixed() + '%.',
{ autoClose: 3000 }
);
}
} else {
this._previousWarn = false;
}
Expand Down

0 comments on commit aa98daf

Please sign in to comment.