Skip to content

Commit b28f654

Browse files
diningPhilosopher64Prabhakar Kumar
authored andcommitted
Introduces environment variable MWI_SHUTDOWN_ON_IDLE_TIMEOUT to specify the idle time after which matlab-proxy will shutdown. See [Advanced-Usage.md](https://github.com/mathworks/matlab-proxy/blob/main/Advanced-Usage.md) for more information.
fixes #10
1 parent 3669330 commit b28f654

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1999
-529
lines changed

Advanced-Usage.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ The following table describes all the environment variables that you can set to
3232
| **MWI_CUSTOM_MATLAB_ROOT** | string (optional) | `"/path/to/matlab/root/"` | Optionally, provide a custom path to MATLAB root. For more information see [Adding MATLAB to System Path](#adding-matlab-to-system-path) |
3333
| **MWI_PROCESS_START_TIMEOUT** | integer (optional) | `1234` | This field controls the time (in seconds) for which `matlab-proxy` waits for the processes it spins up, viz: MATLAB & Xvfb, to respond. By default, this value is `600 seconds`. A timeout could either indicate an issue with the spawned processes or be a symptom of a resource-constrained environment. Increase this value if your environment needs more time for the spawned processes to start.|
3434
| **MWI_MATLAB_STARTUP_SCRIPT** | string (optional) | `"addpath('/path/to/a/folder'), c=12"` | Executes string provided at MATLAB startup. For details, see [Run Custom MATLAB Startup Code](#run-custom-matlab-startup-code) |
35+
| **MWI_SHUTDOWN_ON_IDLE_TIMEOUT** | integer (optional) | 60 | Defines the duration in minutes, that `matlab-proxy` remains idle before shutting down. When you do not set the variable, `matlab-proxy` will not shutdown when idle. For details, [see Shutdown on Idle](#shutdown-on-idle).
36+
37+
## Shutdown on Idle
38+
39+
Set the environment variable `MWI_SHUTDOWN_ON_IDLE_TIMEOUT` to the number of minutes with no user activity after which matlab-proxy will shutdown.
40+
41+
This timer resets when we detect:
42+
* Usage of MATLAB from the Desktop
43+
* Execution of MATLAB code
44+
* Execution of MATLAB code from jupyter notebooks
45+
46+
<p align="center">
47+
<img width="800" src="./img/shutdown_warning.png">
48+
</p>
49+
50+
Use this environment variable to clean up idle system resources.
3551

3652
## Adding MATLAB to System Path
3753

bla.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def example_function():
2+
try:
3+
# Some code that may raise an exception
4+
x = 1 / 0
5+
except ZeroDivisionError:
6+
print("Caught ZeroDivisionError")
7+
8+
print("This should not print if OSError is raised")
9+
10+
11+
try:
12+
example_function()
13+
except OSError as e:
14+
print(f"Caught an OSError: {e}")
15+
16+
print("Execution continues here if OSError is caught")

gui/package-lock.json

Lines changed: 101 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gui/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"clsx": "^1.1.1",
77
"cross-fetch": "^3.0.6",
88
"crypto-js": "4.2.0",
9+
"postcss": "^8.4.38",
910
"react": "^16.13.1",
1011
"react-dom": "^16.13.1",
1112
"react-draggable": "^4.4.3",
@@ -16,7 +17,8 @@
1617
"react-use": "^15.3.4",
1718
"redux": "^4.0.5",
1819
"redux-thunk": "^2.3.0",
19-
"reselect": "^4.0.0"
20+
"reselect": "^4.0.0",
21+
"resolve-url-loader": "^5.0.0"
2022
},
2123
"scripts": {
2224
"start": "react-scripts start",

gui/src/actionCreators/actionCreators.spec.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe.each([
3636
[actionCreators.requestSetLicensing, { type: actions.REQUEST_SET_LICENSING }],
3737
[actionCreators.requestStopMatlab, { type: actions.REQUEST_STOP_MATLAB, status: 'stopping' }],
3838
[actionCreators.requestStartMatlab, { type: actions.REQUEST_START_MATLAB, status: 'starting' }],
39-
[actionCreators.requestTerminateIntegration, { type: actions.REQUEST_TERMINATE_INTEGRATION }]
39+
[actionCreators.requestShutdownIntegration, { type: actions.REQUEST_SHUTDOWN_INTEGRATION }]
4040
])('Test Request actionCreators', (method, expectedAction) => {
4141
test(`check if an action of type ${expectedAction.type} is returned when method actionCreator.${method.name}() is called`, () => {
4242
expect(method()).toEqual(expectedAction);
@@ -48,7 +48,7 @@ describe.each([
4848
[actionCreators.receiveStopMatlab, { matlabStatus: 'down' }, { type: actions.RECEIVE_STOP_MATLAB, status: { matlabStatus: 'down' } }],
4949
[actionCreators.receiveStartMatlab, { matlabStatus: 'up' }, { type: actions.RECEIVE_START_MATLAB, status: { matlabStatus: 'up' } }],
5050
[actionCreators.receiveError, { message: 'ERROR: License Manager Error -9', logs: null }, { type: actions.RECEIVE_ERROR, error: { message: 'ERROR: License Manager Error -9', logs: null } }],
51-
[actionCreators.receiveTerminateIntegration, { licensing: {} }, { type: actions.RECEIVE_TERMINATE_INTEGRATION, status: { licensing: {} }, loadUrl: '../' }]
51+
[actionCreators.requestShutdownIntegration, {}, { type: actions.REQUEST_SHUTDOWN_INTEGRATION }]
5252
])('Test Receive actionCreators', (method, input, expectedAction) => {
5353
test(`check if an action of type ${expectedAction.type} is returned when method actionCreator.${method.name}() is called`, () => {
5454
expect(method(input)).toEqual(expectedAction);
@@ -429,32 +429,6 @@ describe('Test Async actionCreators', () => {
429429
});
430430
});
431431

432-
it('should dispatch REQUEST_TERMINATE_INTEGRATION and RECEIVE_TERMINATE_INTEGRATION when we terminate the integration', () => {
433-
fetchMock.deleteOnce('./terminate_integration', {
434-
body: {
435-
matlab: {
436-
status: 'down'
437-
},
438-
licensing: null
439-
},
440-
headers: { 'content-type': 'application/json' }
441-
});
442-
443-
const expectedActionTypes = [
444-
actions.REQUEST_TERMINATE_INTEGRATION,
445-
actions.RECEIVE_TERMINATE_INTEGRATION
446-
];
447-
448-
return store
449-
.dispatch(actionCreators.fetchTerminateIntegration())
450-
.then(() => {
451-
const receivedActions = store.getActions();
452-
expect(receivedActions.map((action) => action.type)).toEqual(
453-
expectedActionTypes
454-
);
455-
});
456-
});
457-
458432
it('should dispatch REQUEST_STOP_MATLAB AND RECEIVE_STOP_MATLAB when we stop matlab', () => {
459433
fetchMock.putOnce('./start_matlab', {
460434
body: {

gui/src/actionCreators/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import {
88
RECEIVE_SERVER_STATUS,
99
REQUEST_SET_LICENSING,
1010
REQUEST_UPDATE_LICENSING,
11-
REQUEST_TERMINATE_INTEGRATION,
11+
REQUEST_SHUTDOWN_INTEGRATION,
1212
REQUEST_STOP_MATLAB,
1313
REQUEST_START_MATLAB,
1414
REQUEST_ENV_CONFIG,
1515
RECEIVE_SET_LICENSING,
1616
RECEIVE_UPDATE_LICENSING,
17-
RECEIVE_TERMINATE_INTEGRATION,
17+
RECEIVE_SHUTDOWN_INTEGRATION,
1818
RECEIVE_STOP_MATLAB,
1919
RECEIVE_START_MATLAB,
2020
RECEIVE_ERROR,
@@ -162,15 +162,15 @@ export function receiveUpdateLicensing (status) {
162162
};
163163
}
164164

165-
export function requestTerminateIntegration () {
165+
export function requestShutdownIntegration () {
166166
return {
167-
type: REQUEST_TERMINATE_INTEGRATION
167+
type: REQUEST_SHUTDOWN_INTEGRATION
168168
};
169169
}
170170

171-
export function receiveTerminateIntegration (status) {
171+
export function receiveShutdownIntegration (status) {
172172
return {
173-
type: RECEIVE_TERMINATE_INTEGRATION,
173+
type: RECEIVE_SHUTDOWN_INTEGRATION,
174174
status,
175175
loadUrl: '../'
176176
};
@@ -374,7 +374,7 @@ export function fetchUnsetLicensing () {
374374
};
375375
}
376376

377-
export function fetchTerminateIntegration () {
377+
export function fetchShutdownIntegration () {
378378
return async function (dispatch, getState) {
379379
const options = {
380380
method: 'DELETE',
@@ -383,10 +383,10 @@ export function fetchTerminateIntegration () {
383383
credentials: 'same-origin'
384384
};
385385

386-
dispatch(requestTerminateIntegration());
387-
const response = await fetchWithTimeout(dispatch, './terminate_integration', options, 15000);
386+
dispatch(requestShutdownIntegration());
387+
const response = await fetchWithTimeout(dispatch, './shutdown_integration', options, 15000);
388388
const data = await response.json();
389-
dispatch(receiveTerminateIntegration(data));
389+
dispatch(receiveShutdownIntegration(data));
390390
};
391391
}
392392

0 commit comments

Comments
 (0)