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
|
||||
userEmailOpenCLI: string
|
||||
userOpenCLI: string
|
||||
inventory: string
|
||||
inventory: any
|
||||
latestScenario?: {
|
||||
name: string
|
||||
time: number
|
||||
|
|
@ -109,7 +109,7 @@ export default class LineConnection {
|
|||
private outputScenario: string
|
||||
// private bufferCommand: string
|
||||
public dataDPELP: DataDPELP | string
|
||||
private retryConnect: number
|
||||
private listScenarios: number[]
|
||||
public handleClearLine: () => void
|
||||
|
||||
constructor(config: LineConfig, socketIO: any, handleClearLine: () => void) {
|
||||
|
|
@ -134,7 +134,7 @@ export default class LineConnection {
|
|||
issues: ['No data'],
|
||||
summary: '',
|
||||
}
|
||||
this.retryConnect = 0
|
||||
this.listScenarios = []
|
||||
this.handleClearLine = handleClearLine
|
||||
}
|
||||
|
||||
|
|
@ -445,7 +445,7 @@ export default class LineConnection {
|
|||
|
||||
const logScenarios = this.outputScenario
|
||||
const data = textfsmResults(logScenarios, '')
|
||||
let pid = ''
|
||||
let pid = this.config.inventory?.pid || ''
|
||||
try {
|
||||
data.forEach((item) => {
|
||||
if (item?.textfsm && isValidJson(item?.textfsm)) {
|
||||
|
|
@ -469,9 +469,10 @@ export default class LineConnection {
|
|||
item.textfsm = JSON.parse(item.textfsm)
|
||||
}
|
||||
})
|
||||
const scenario = await detectScenarioByModel(pid)
|
||||
// console.log(pid, scenario)
|
||||
const scenario = await detectScenarioByModel(pid, this.listScenarios)
|
||||
console.log(pid, scenario?.title, this.listScenarios)
|
||||
if (scenario && scenario.id !== script.id) {
|
||||
this.listScenarios.push(scenario.id)
|
||||
this.outputScenario = ''
|
||||
this.runScript(scenario, userName)
|
||||
// this.socketIO.emit('confirm_scenario', {
|
||||
|
|
@ -510,7 +511,7 @@ export default class LineConnection {
|
|||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
this.listScenarios = []
|
||||
this.outputScenario = ''
|
||||
resolve(true)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -307,12 +307,13 @@ export function sendMessageToZulip(
|
|||
}
|
||||
|
||||
// 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')
|
||||
const normalizedModel = model.trim().toUpperCase()
|
||||
let matched: { scenario: Scenario; score: number } | null = null
|
||||
|
||||
for (const scenario of scenarios) {
|
||||
if (listScenarios.includes(scenario.id)) continue
|
||||
const seriesList: string[] = Array.isArray(scenario.series)
|
||||
? scenario.series
|
||||
: JSON.parse(scenario.series || '[]')
|
||||
|
|
|
|||
|
|
@ -1025,6 +1025,7 @@ export class WebSocketIo {
|
|||
}
|
||||
|
||||
async waitUntilAllReady(lineIds: number[]) {
|
||||
await sleep(5000)
|
||||
return new Promise<any[]>((resolve) => {
|
||||
const interval = setInterval(() => {
|
||||
let allReady = true
|
||||
|
|
|
|||
Loading…
Reference in New Issue