I have been working on an ERP software which is used by ~25 users across departments.
The coordination across departments during a deploy (before shutdown and post restart) becomes a pain. Unfortunately, the company does not use chat tools which can be used for broadcast. Instead, the communication is done using phone or in-person.
To resolve this, I was asked if software itself could intimate the user when it is about to shutdown, and once its restarted.
Do not overengineer
I started looking into websockets and other forms of push communication, though quickly realized it would be an overkill. Since there are only 25 users polling becomes the simplest solution.
Server side - APIs for checking current status and updating status to ‘shutdown’
- API for shutdown can either be based on authentication or a secret token so that its not misused (mine is on a self-contained LAN and not internet, so I used token)
- API for startup can be added if required. Considering, once deployed, the atomic boolean will be reinitialized automatically.
- AtomicBoolean is used to avoid caching issues (Volatile can also be used).
- During status check, return ‘ok’ for normal process, and ‘shutdown’ if boolean is false, indicating shutdown will begin shortly.
Server side - Permissions
- Ensure the status check URL is open for all (no authentication).
This will depend on your session implementation. In our case once server is restarted, the sessions are invalidated (user checking status after server restart will be redirected to login in that case, which we want to avoid).
UI side - Poll for status and alert if shutdown message received
- Use $.ajax call to check for status, and alert user accordingly.
- Use JQuery’s timeout to periodically call the same method. This is done by calling timeout in onComplete callback (avoid calling timeout in success callback, because once server shuts down, the ajax call will fail and next timeout will not be set).
- In case, the JQuery library is being loaded after this code is called. Use defer (as shown below) to wait for JQuery to load.
- Use modal in case you want the alert to be pretty. I used the native one.