At User Support we occasionally get questions about the termination of WebUI sessions; for instance as follows:
We have a project where the premaintermination and maintermination both contain the statement “return 1”.
Separately, we have a library in which we want to run some checks and empty some parameters in the library pre termination. However, we observe that when the app is uploaded, the PreLibraryTermination and LibraryTermination are not ran.
We’ve noticed this because when re-opening the same app within a few minutes, the data session is still active, and parameters that should be empty because we empty them both in the library initialization and termination, still contain data.
Understandably, if you are not aware of the termination protocol of AIMMS WebUI sessions, this can be confusing.
Let me share some details about the termination protocol for an AIMMS WebUI session first:
- Background: An AIMMS WebUI session consists of two communicating processes:
- A process in the browser of the end-user interacting with that end-user
- A process running on central hardware of the AIMMS PRO system, computing values as prescribed by the AIMMS model. I call this the data session.
- Observation: When an end-user closes the browser tab containing the visuals of an AIMMS WebUI session, this can be accidental or on purpose.
- Choice: When this tab-close is accidental, the end-user has five minutes to recover by launching the same application again from the AIMMS PRO portal; the AIMMS data session will reconnect such that the end-user has access to latest data again.
- Choice: When this tab-close is on purpose, the data session ends silently after five minutes. When the data session is ended, the termination procedures are ran.
There are several ways to alter this protocol:
- The timeout of five minutes can be adapted, see https://how-to.aimms.com/Articles/342/342-WebUI-Session-Timeout-Extension.html
- An admin of AIMMS PRO can terminate the data session via the AIMMS PRO portal, tab configuration > active data sessions.
- Adding a "bye” button, which, when clicked, ends the data session. Note that the browser tab of the WebUI session is not closed, but its contents are replaced by the AIMMS PRO portal.
A "bye” button can be implemented as follows:
First add the procedure pr_goodBye to the application defined as follows:
Procedure pr_goodBye {
Body: {
if pro::GetPROEndPoint() then
if DirectoryExists("./MainProject/WebUI") then
pro::sessionmanager::FinishSession(); ! Stopping data session of a published WebUI application.
else
ExitAimms(); ! stopping data session of a published WinUI application.
endif ;
else
ExitAimms(); ! Stopping a session being run in AIMMS Developer.
endif ;
}
Comment: "Stop data session via the door at the far lower right corner.";
}
As it is your project, you can, of course, adapt the above to your needs, for instance to start by verifying that all data is saved.
Then link the procedure pr_goodBye to a button titled "Bye” in the WebUI, or use the status bar by adding the following data to it:
('9', 'header' ) : "",
('9', 'icon' ) : "aimms-exit",
('9', 'color' ) : "",
('9', 'text' ) : "Bye",
('9', 'tooltip' ) : "",
('9', 'procedure' ) : "pr_goodBye",
('9', 'state' ) : "Active"
which will give the impression of an exit door in the lower right of the screen: