Enhance scenario detection and tracking logic
Updated LineConnection to track processed scenario IDs and prevent duplicate scenario detection by passing a list of previously detected scenarios to detectScenarioByModel. Modified detectScenarioByModel to skip scenarios already in the list. Added a delay in waitUntilAllReady to ensure readiness before proceeding.
This commit is contained in:
parent
6e282c42bd
commit
fef82cb233
|
|
@ -42,7 +42,7 @@ interface LineConfig {
|
||||||
openCLI: boolean
|
openCLI: boolean
|
||||||
userEmailOpenCLI: string
|
userEmailOpenCLI: string
|
||||||
userOpenCLI: string
|
userOpenCLI: string
|
||||||
inventory: string
|
inventory: any
|
||||||
latestScenario?: {
|
latestScenario?: {
|
||||||
name: string
|
name: string
|
||||||
time: number
|
time: number
|
||||||
|
|
@ -109,7 +109,7 @@ export default class LineConnection {
|
||||||
private outputScenario: string
|
private outputScenario: string
|
||||||
// private bufferCommand: string
|
// private bufferCommand: string
|
||||||
public dataDPELP: DataDPELP | string
|
public dataDPELP: DataDPELP | string
|
||||||
private retryConnect: number
|
private listScenarios: number[]
|
||||||
public handleClearLine: () => void
|
public handleClearLine: () => void
|
||||||
|
|
||||||
constructor(config: LineConfig, socketIO: any, handleClearLine: () => void) {
|
constructor(config: LineConfig, socketIO: any, handleClearLine: () => void) {
|
||||||
|
|
@ -134,7 +134,7 @@ export default class LineConnection {
|
||||||
issues: ['No data'],
|
issues: ['No data'],
|
||||||
summary: '',
|
summary: '',
|
||||||
}
|
}
|
||||||
this.retryConnect = 0
|
this.listScenarios = []
|
||||||
this.handleClearLine = handleClearLine
|
this.handleClearLine = handleClearLine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,7 +445,7 @@ export default class LineConnection {
|
||||||
|
|
||||||
const logScenarios = this.outputScenario
|
const logScenarios = this.outputScenario
|
||||||
const data = textfsmResults(logScenarios, '')
|
const data = textfsmResults(logScenarios, '')
|
||||||
let pid = ''
|
let pid = this.config.inventory?.pid || ''
|
||||||
try {
|
try {
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
if (item?.textfsm && isValidJson(item?.textfsm)) {
|
if (item?.textfsm && isValidJson(item?.textfsm)) {
|
||||||
|
|
@ -469,9 +469,10 @@ export default class LineConnection {
|
||||||
item.textfsm = JSON.parse(item.textfsm)
|
item.textfsm = JSON.parse(item.textfsm)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const scenario = await detectScenarioByModel(pid)
|
const scenario = await detectScenarioByModel(pid, this.listScenarios)
|
||||||
// console.log(pid, scenario)
|
console.log(pid, scenario?.title, this.listScenarios)
|
||||||
if (scenario && scenario.id !== script.id) {
|
if (scenario && scenario.id !== script.id) {
|
||||||
|
this.listScenarios.push(scenario.id)
|
||||||
this.outputScenario = ''
|
this.outputScenario = ''
|
||||||
this.runScript(scenario, userName)
|
this.runScript(scenario, userName)
|
||||||
// this.socketIO.emit('confirm_scenario', {
|
// this.socketIO.emit('confirm_scenario', {
|
||||||
|
|
@ -510,7 +511,7 @@ export default class LineConnection {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
this.listScenarios = []
|
||||||
this.outputScenario = ''
|
this.outputScenario = ''
|
||||||
resolve(true)
|
resolve(true)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -307,12 +307,13 @@ export function sendMessageToZulip(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch scenario with key longer
|
// Catch scenario with key longer
|
||||||
export const detectScenarioByModel = async (model: string) => {
|
export const detectScenarioByModel = async (model: string, listScenarios: number[]) => {
|
||||||
let scenarios = await Scenario.query().preload('brand').preload('category')
|
let scenarios = await Scenario.query().preload('brand').preload('category')
|
||||||
const normalizedModel = model.trim().toUpperCase()
|
const normalizedModel = model.trim().toUpperCase()
|
||||||
let matched: { scenario: Scenario; score: number } | null = null
|
let matched: { scenario: Scenario; score: number } | null = null
|
||||||
|
|
||||||
for (const scenario of scenarios) {
|
for (const scenario of scenarios) {
|
||||||
|
if (listScenarios.includes(scenario.id)) continue
|
||||||
const seriesList: string[] = Array.isArray(scenario.series)
|
const seriesList: string[] = Array.isArray(scenario.series)
|
||||||
? scenario.series
|
? scenario.series
|
||||||
: JSON.parse(scenario.series || '[]')
|
: JSON.parse(scenario.series || '[]')
|
||||||
|
|
|
||||||
|
|
@ -1025,6 +1025,7 @@ export class WebSocketIo {
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitUntilAllReady(lineIds: number[]) {
|
async waitUntilAllReady(lineIds: number[]) {
|
||||||
|
await sleep(5000)
|
||||||
return new Promise<any[]>((resolve) => {
|
return new Promise<any[]>((resolve) => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
let allReady = true
|
let allReady = true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue