Modify the processing to consider the active queue length instead of in_progress only

This commit is contained in:
Daniel Abrao 2024-04-12 08:04:46 -03:00 committed by psychedelicious
parent bb330d50a6
commit a459361376

View File

@ -8,13 +8,17 @@ const log = logger('socketio');
const updatePageTitle = (itemStatus: string) => {
const baseString: string = document.title.replace('(1) ', '');
document.title = itemStatus === 'in_progress' ? `(1) ${baseString}` : baseString;
const updatePageTitle = (activeQueueLength: number) => {
const baseString: string = document.title.replace(/\(\d+\)/ , '');
document.title = activeQueueLength > 0 ? `(${activeQueueLength}) ${baseString}` : baseString;
};
const updatePageFavicon = (itemStatus: string) => {
const updatePageFavicon = (activeQueueLength: number) => {
const InvokeLogoSVG: string = 'assets/images/invoke-favicon.svg';
const InvokeAlertLogoSVG: string = 'assets/images/invoke-alert-favicon.svg';
const faviconEl: HTMLLinkElement = document.getElementById('invoke-favicon') as HTMLLinkElement;
faviconEl.href = itemStatus === 'in_progress' ? InvokeAlertLogoSVG : InvokeLogoSVG;
faviconEl.href = activeQueueLength > 0 ? InvokeAlertLogoSVG : InvokeLogoSVG;
};
export const addSocketQueueItemStatusChangedEventListener = (startAppListening: AppStartListening) => {
@ -24,6 +28,9 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
// we've got new status for the queue item, batch and queue
const { queue_item, batch_status, queue_status } = action.payload.data;
// Keep track of the active queue length by summing up pending and in_progress count
const activeQueueLength: number = (queue_status.pending + queue_status.in_progress) || 0;
log.debug(action.payload, `Queue item ${queue_item.item_id} status updated: ${queue_item.status}`);
// Update this specific queue item in the list of queue items (this is the queue item DTO, without the session)
@ -67,8 +74,8 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
queueApi.util.invalidateTags(['CurrentSessionQueueItem', 'NextSessionQueueItem', 'InvocationCacheStatus'])
);
updatePageTitle(queue_item.status);
updatePageFavicon(queue_item.status);
updatePageTitle(activeQueueLength);
updatePageFavicon(activeQueueLength);
},
});
};