Open Event Web app handles multiple requests from the client using task queue, every request from client is put in the job queue and handled one at a time. The only log shown to client was either ‘waiting’ or ‘processing’, so we need to show additional logs like request waiting number as well. The logs are shown in real time using sockets.
How to add logs?
The logs of any request are shown to the client in real time using socket emit and listener events. Whenever any data is to be displayed inside the logs, the server emits an event with the data. The socket listens to the event and appends the data received to the logs section of the view.
Creating helper for emitting data
The helper function named ‘logger’ is created which emits the event ‘buildLog’ whenever it is called with the data being passed as arguments. Every time a message is passed to this procedure, it adds it to array of objects containing the data.
Updating logs in real time
The helper created above emits the event ‘buildLog’, the socket on listening this event appends the data inside logs division with the data received from the helper while emitting the event.
Add request waiting number
Whenever a new request is received from the client the server emits the event ‘waiting’ if any other job is currently being processed. The helper above is used to add request waiting number to the logs.
Add status in logs
On listening the event named ‘waiting’ the status is updated to ‘waiting’ in the view and is shown to the client.
Update request waiting number
Whenever a job is started being processed from the queue, the waiting number of all the requests in the ready queue is updated. The socket connection for corresponding request is obtained from the main socket object(socketObj) which updates whenever a new request comes from the client.
- Open Event Webapp Repository: https://github.com/fossasia/open-event-webapp
- Pull Request: https://github.com/fossasia/open-event-webapp/pull/1981
- Issue : https://github.com/fossasia/open-event-webapp/issues/1980