Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: maintenance mode websocket #469

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

RubenLWF
Copy link

Description

This PR creates a websocket server that we will send a message over once the PUT /server-settings/maintenance-mode endpoint is called. This message can be used by the POS to show the maintenance screen as soon as maintenance mode is enabled without having to be refreshed.

Related issues/external references

Types of changes

  • New feature (non-breaking change which adds functionality)

@JustSamuel
Copy link
Contributor

JustSamuel commented Feb 14, 2025

Nice to see you are working on the backend! :D

Small issue / food for thought about this new feature though, in production we run 4 processes for the main endpoints and one for cron jobs. The API calls are distributed evenly over these 4 processes, which is nice for high load situtions.

The issue, as you might guess, is that the process that receives the server-setting update might not be the same as the one storing the clients (in the end, you are only connected to a single process with the websocket).

Possible solutions include stuff like redis or storing jobs in the db, but I think this solution works best:
https://socket.io/docs/v4/pm2/

Also, second remark. I think it would be a bit nicer if we create some pub-sub type structure? (and possible a authentication layer or handshake) In the end it would be nice to use this to get live transaction history on the POS without having to pol continuously. To this end I suggest a structure where you can connect to specific topic (transactions, topups, etc). However it should not be so complex that we are reworking our CRUD endpoints into pubsub topics, but I think a set of predefined topics could get is quite a distance.

Maybe just a topic per entity? And also the ability to specify an Id if the entity has one, e.g. TOPIC transactions or TOPIC point-of-sale/1. To this end I think moving everything to database subscribers would even be nicer as then you could complete separate the websocket from the rest of the backend.

Last dump edit: we could create an WSAppDataSource which includes all the subscribers, and based on functions within those subscribers we could effectively send out messages, al whilst keeping the ws in its own process.

@@ -45,6 +46,7 @@ export default class ServerSettingsController extends BaseController {
public constructor(options: BaseControllerOptions) {
super(options);
this.logger.level = process.env.LOG_LEVEL;
WebSocketService.initiateWebSocket();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this to the index?

* @module websocket
*/

export default class WebSocketService {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest a singleton class like the ServerSettings

src/service/websocket-service.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants