Run AI classification in background with SignalR notifications
Move the classify-uncategorized endpoint from synchronous to async. The controller now queues a ClassificationJob to an unbounded channel and returns 202 Accepted. A new BackgroundService processes jobs and pushes results (or errors) to the user via SignalR. The frontend listens for the AiClassificationComplete event and surfaces it in the notification system. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { HubConnectionBuilder, HubConnection, LogLevel } from '@microsoft/signalr'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import type { AppNotification, FileImportNotification, BankSyncNotification } from '@/types'
|
||||
import type { AppNotification, FileImportNotification, BankSyncNotification, AiClassificationNotification } from '@/types'
|
||||
|
||||
const notifications = ref<AppNotification[]>([])
|
||||
const isConnected = ref(false)
|
||||
@@ -42,6 +42,16 @@ function connect() {
|
||||
})
|
||||
})
|
||||
|
||||
connection.on('AiClassificationComplete', (data: AiClassificationNotification) => {
|
||||
notifications.value.unshift({
|
||||
id: crypto.randomUUID(),
|
||||
type: 'AiClassificationComplete',
|
||||
data,
|
||||
timestamp: new Date().toISOString(),
|
||||
read: false
|
||||
})
|
||||
})
|
||||
|
||||
connection.onclose(() => {
|
||||
isConnected.value = false
|
||||
})
|
||||
|
||||
@@ -414,10 +414,17 @@ export interface BankSyncNotification {
|
||||
status: string
|
||||
}
|
||||
|
||||
export interface AiClassificationNotification {
|
||||
totalUncategorized: number
|
||||
classified: number
|
||||
skipped: number
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface AppNotification {
|
||||
id: string
|
||||
type: 'FileImportReady' | 'BankSyncComplete'
|
||||
data: FileImportNotification | BankSyncNotification
|
||||
type: 'FileImportReady' | 'BankSyncComplete' | 'AiClassificationComplete'
|
||||
data: FileImportNotification | BankSyncNotification | AiClassificationNotification
|
||||
timestamp: string
|
||||
read: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user