fix
This commit is contained in:
1 parent
08c620ee68
commit
dae82eeff2
5 files changed
+114
-11
No files matched your search
@@ -86,6 +86,8 @@ export class CWMPTaskQueue extends EventEmitter {
|
||||
private tasks: Map<string, CWMPTask> = new Map()
|
||||
private deviceQueues: Map<string, string[]> = new Map()
|
||||
private taskCallbacks: Map<string, (result: TaskResult) => Promise<string>> = new Map()
|
||||
/** Tracks the most recently created task per device (set by addTask) */
|
||||
private lastCreatedTaskIdByDevice: Map<string, string> = new Map()
|
||||
|
||||
/**
|
||||
* Adds a task with callback (legacy-compatible API used by DeviceActionExecutor)
|
||||
@@ -108,6 +110,9 @@ export class CWMPTaskQueue extends EventEmitter {
|
||||
cwmpTask.status = TaskStatus.SENT
|
||||
}
|
||||
|
||||
// Track the most recent task created for this device so callers can retrieve its ID
|
||||
this.lastCreatedTaskIdByDevice.set(JSON.stringify(deviceId), cwmpTask.id)
|
||||
|
||||
// Generate CWMP envelope
|
||||
const builder = CWMPTaskQueue.task_map[taskType]
|
||||
if (typeof builder !== 'function') {
|
||||
@@ -217,20 +222,28 @@ export class CWMPTaskQueue extends EventEmitter {
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the most recently created task for a device (via addTask).
|
||||
* Used by the state machine manager to correlate responses with in-flight tasks
|
||||
* that were created directly by state handlers (not served from the external queue).
|
||||
*/
|
||||
getLastCreatedTaskId(deviceId: DeviceId): string | undefined {
|
||||
return this.lastCreatedTaskIdByDevice.get(JSON.stringify(deviceId))
|
||||
}
|
||||
|
||||
clearPendingTasksForDevice(deviceId: DeviceId): void {
|
||||
const deviceKey = JSON.stringify(deviceId)
|
||||
const queue = this.deviceQueues.get(deviceKey) || []
|
||||
const keep: string[] = []
|
||||
// Clear ALL tasks (PENDING and SENT) — after session completion, no task
|
||||
// from the previous session should bleed into the next one. Tasks that were
|
||||
// already SENT (created by state-machine states via addTask()) are ghost
|
||||
// entries that would otherwise be served to the next session.
|
||||
for (const taskId of queue) {
|
||||
const t = this.tasks.get(taskId)
|
||||
if (t && t.status === TaskStatus.SENT) {
|
||||
keep.push(taskId)
|
||||
continue
|
||||
}
|
||||
this.tasks.delete(taskId)
|
||||
this.taskCallbacks.delete(taskId)
|
||||
}
|
||||
this.deviceQueues.set(deviceKey, keep)
|
||||
this.deviceQueues.set(deviceKey, [])
|
||||
this.lastCreatedTaskIdByDevice.delete(deviceKey)
|
||||
}
|
||||
|
||||
private generateTaskId(deviceId: DeviceId, type: string): string {
|
||||
|
||||
Reference in new issue
Block a user