Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
366c550
migrate manager menu items
christian-byrne Apr 9, 2025
2aed31a
Update locales [skip ci]
invalid-email-address Apr 9, 2025
1f41367
switch to v2 manager API endpoints
christian-byrne Apr 9, 2025
363a46b
re-arrange menu items
christian-byrne Apr 11, 2025
5867103
await promises. update settings schema
christian-byrne Apr 14, 2025
7c14b26
move legacy option to startup arg
christian-byrne Apr 14, 2025
d3a629c
Add banner indicating how to use legacy manager UI
christian-byrne Apr 14, 2025
3c8adf4
Update locales [skip ci]
invalid-email-address Apr 14, 2025
eee3b74
add "Check for Updates", "Install Missing" menu items
christian-byrne Apr 14, 2025
dc2a470
Update locales [skip ci]
invalid-email-address Apr 14, 2025
05ec65f
use correct response shape
christian-byrne Apr 14, 2025
3862d78
improve command names
christian-byrne Apr 14, 2025
4a67a83
dont show missing nodes button in legacy manager mode
christian-byrne Apr 15, 2025
ced03ce
[Update to v2 API] update WS done message
christian-byrne Apr 15, 2025
7725b87
Update locales [skip ci]
invalid-email-address Apr 26, 2025
b348669
[manager] Update type definitions and schemas for menu items migration
christian-byrne Jun 13, 2025
f241b7f
[manager] Update core services for new manager API
christian-byrne Jun 13, 2025
ba1d067
[manager] Update composables and state management
christian-byrne Jun 13, 2025
b683a81
[manager] Update UI components for new manager interface
christian-byrne Jun 13, 2025
39ad018
[manager] Update tests for new manager API
christian-byrne Jun 13, 2025
5e43715
[manager] Fix test failures and missing type definitions
christian-byrne Jun 14, 2025
4249fe7
fix rebase errors
christian-byrne Jun 21, 2025
0f9d1f8
Update locales [skip ci]
invalid-email-address Jun 21, 2025
60e2f14
[Manager] Filter task queue and history by client id (#4241)
christian-byrne Jun 21, 2025
096e0c9
fix failed task tab state binding
christian-byrne Jun 22, 2025
8fbd076
[Manager] Fix: failed tasks logs not correctly partitioned in UI (#4242)
christian-byrne Jun 22, 2025
0f7e3f7
[tests] Update useServerLogs test to handle task-started events
christian-byrne Jun 22, 2025
dc85896
fix: logs stops listening after 1st of multiple queue tasks
christian-byrne Jun 23, 2025
a83a7fa
remove the temporary check for legacy custom node version of manager
christian-byrne Jun 23, 2025
babe324
[tests] Update useServerLogs test after log subscription change
christian-byrne Jun 23, 2025
558cfcc
[Manager] Add update all button functionality
viva-jinyi Jun 24, 2025
1cb94ca
[Manager] “Restarting” state after clicking restart button (#4269)
viva-jinyi Jun 26, 2025
7073c9d
fix rebase error
christian-byrne Jul 11, 2025
2e2647d
Update locales [skip ci]
invalid-email-address Jul 11, 2025
730b278
[test] Update PackVersionBadge test to use role selector instead of B…
viva-jinyi Jul 11, 2025
c28d451
migrate manager menu items
christian-byrne Apr 9, 2025
588bd99
Update locales [skip ci]
invalid-email-address Apr 9, 2025
de6ed34
switch to v2 manager API endpoints
christian-byrne Apr 9, 2025
54a0981
re-arrange menu items
christian-byrne Apr 11, 2025
eb5c49f
await promises. update settings schema
christian-byrne Apr 14, 2025
aba2e5e
move legacy option to startup arg
christian-byrne Apr 14, 2025
f8953a8
Add banner indicating how to use legacy manager UI
christian-byrne Apr 14, 2025
e780e1d
Update locales [skip ci]
invalid-email-address Apr 14, 2025
b01056e
add "Check for Updates", "Install Missing" menu items
christian-byrne Apr 14, 2025
bdd1230
Update locales [skip ci]
invalid-email-address Apr 14, 2025
1aee434
use correct response shape
christian-byrne Apr 14, 2025
f1610db
improve command names
christian-byrne Apr 14, 2025
4f94707
dont show missing nodes button in legacy manager mode
christian-byrne Apr 15, 2025
8075db4
[Update to v2 API] update WS done message
christian-byrne Apr 15, 2025
3fdbc28
Restore lost work from manager/menu-items-migration feature branch
christian-byrne Aug 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Manager] Filter task queue and history by client id (#4241)
  • Loading branch information
christian-byrne committed Jul 11, 2025
commit 60e2f14516ca53bfc591c979fa2d03116b70a1fc
89 changes: 60 additions & 29 deletions src/composables/useManagerQueue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEventListener, whenever } from '@vueuse/core'
import { pickBy } from 'lodash'
import { Ref, computed, ref } from 'vue'

import { api } from '@/scripts/api'
import { app } from '@/scripts/app'
import { useDialogService } from '@/services/dialogService'
import { components } from '@/types/generatedManagerTypes'

Expand All @@ -12,6 +13,9 @@ type ManagerTaskHistory = Record<
type ManagerTaskQueue = components['schemas']['TaskStateMessage']
type ManagerWsTaskDoneMsg = components['schemas']['MessageTaskDone']
type ManagerWsTaskStartedMsg = components['schemas']['MessageTaskStarted']
type QueueTaskItem = components['schemas']['QueueTaskItem']
type HistoryTaskItem = components['schemas']['TaskHistoryItem']
type Task = QueueTaskItem | HistoryTaskItem

const MANAGER_WS_TASK_DONE_NAME = 'cm-task-completed'
const MANAGER_WS_TASK_STARTED_NAME = 'cm-task-started'
Expand All @@ -35,55 +39,82 @@ export const useManagerQueue = (
taskQueue.value.pending_queue.length
)

const updateProcessingState = () => {
/**
* Update the processing state based on the current queue length.
* If the queue is empty, or all tasks in the queue are associated
* with different clients, then this client is not processing any tasks.
*/
const updateProcessingState = (): void => {
isProcessing.value = currentQueueLength.value > 0
}

const allTasksDone = computed(
() => !isProcessing.value && currentQueueLength.value === 0
)
const allTasksDone = computed(() => currentQueueLength.value === 0)
const historyCount = computed(() => Object.keys(taskHistory.value).length)

/**
* Check if a task is associated with this client.
* Task can be from running queue, pending queue, or history.
* @param task - The task to check
* @returns True if the task belongs to this client
*/
const isTaskFromThisClient = (task: Task): boolean =>
task.client_id === app.api.clientId

/**
* Filter queue tasks by client id.
* Ensures that only tasks associated with this client are processed and
* added to client state.
* @param tasks - Array of queue tasks to filter
* @returns Filtered array containing only tasks from this client
*/
const filterQueueByClientId = (tasks: QueueTaskItem[]): QueueTaskItem[] =>
tasks.filter(isTaskFromThisClient)

/**
* Filter history tasks by client id using lodash pickBy for optimal performance.
* Returns a new object containing only tasks associated with this client.
* @param history - The history object to filter
* @returns Filtered history object containing only tasks from this client
*/
const filterHistoryByClientId = (history: ManagerTaskHistory) =>
pickBy(history, isTaskFromThisClient)

/**
* Update task queue and history state with filtered data from server.
* Ensures only tasks from this client are stored in local state.
* @param state - The task state message from the server
*/
const updateTaskState = (state: ManagerTaskQueue) => {
taskQueue.value.running_queue = filterQueueByClientId(state.running_queue)
taskQueue.value.pending_queue = filterQueueByClientId(state.pending_queue)
taskHistory.value = filterHistoryByClientId(state.history)

if (state.installed_packs) {
installedPacks.value = state.installed_packs
}
updateProcessingState()
}

// WebSocket event listener for task done
const cleanupTaskDoneListener = useEventListener(
api,
app.api,
MANAGER_WS_TASK_DONE_NAME,
(event: CustomEvent<ManagerWsTaskDoneMsg>) => {
if (event?.type === MANAGER_WS_TASK_DONE_NAME) {
const { state } = event.detail
taskQueue.value.running_queue = state.running_queue
taskQueue.value.pending_queue = state.pending_queue
taskHistory.value = state.history
if (state.installed_packs) {
console.log(
'Updating installedPacks from WebSocket:',
Object.keys(state.installed_packs)
)
installedPacks.value = state.installed_packs
}
updateProcessingState()
updateTaskState(state)
}
}
)

// WebSocket event listener for task started
const cleanupTaskStartedListener = useEventListener(
api,
app.api,
MANAGER_WS_TASK_STARTED_NAME,
(event: CustomEvent<ManagerWsTaskStartedMsg>) => {
if (event?.type === MANAGER_WS_TASK_STARTED_NAME) {
const { state } = event.detail
taskQueue.value.running_queue = state.running_queue
taskQueue.value.pending_queue = state.pending_queue
taskHistory.value = state.history
if (state.installed_packs) {
console.log(
'Updating installedPacks from WebSocket:',
Object.keys(state.installed_packs)
)
installedPacks.value = state.installed_packs
}
updateProcessingState()
updateTaskState(state)
}
}
)
Expand Down
Loading